Javascript – Cannot find module ‘npmlog’ error message when using npm command


Today is my first day of my first job and after setting up my development environment by updating node and npm on my Mac (OSX) I seem to have broken something. Every time I try to use npm in my commandline (npm init, npm install, etc.) I get this error message:


throw err;

Error: Cannot find module 'npmlog'

at Function.Module._resolveFilename (module.js:337:15)

at Function.Module._load (module.js:287:25)

at Module.require (module.js:366:17)

at require (module.js:385:17)

at /usr/local/lib/node_modules/npm/bin/npm-cli.js:20:13

at Object. (/usr/local/lib/node_modules/npm/bin/npm->cli.js:76:3)

at Module._compile (module.js:425:26)

at Object.Module._extensions..js (module.js:432:10)

at Module.load (module.js:356:32)

at Function.Module._load (module.js:311:12)

There isn't much of an error message to go off and the stack trace isn't helping me all that much either. Here's what I have tried:

  1. Searched around Stackoverflow and though there are similar problems, people have been able to use npm <something> to solve their problem, which I cannot do.
  2. Uninstalling and reinstalling npm – Didn't work because I can't use npm command at all so things like sudo npm uninstall npm -g don't work.
  3. Removed npmlog directory from .npm directory and then cloned the github repo directly to the directory again.

Hopefully one of you have run into this before or have an idea of how to approach it. Any help is appreciated.

Best Solution

Here is one good link Fixing npm On Mac OS X for Homebrew Users.

with following commands when try to upgrade node.js under mac

rm -rf /usr/local/lib/node_modules
brew uninstall node
brew install node --without-npm
echo prefix=~/.npm-packages >> ~/.npmrc
curl -L | sudo sh
Related Question