5

I made the mistake (?) of following the instructions on the npm getting started page and ran

sudo npm install npm -g

Now, no matter what I do, any execution of npm results in this error, whether I run it as sudo or not. Uninstalling and reinstalling node has not helped.

$ sudo npm

module.js:457
    throw err;
    ^

Error: Cannot find module 'npmlog'
    at Function.Module._resolveFilename (module.js:455:15)
    at Function.Module._load (module.js:403:25)
    at Module.require (module.js:483:17)
    at require (internal/module.js:20:19)
    at /usr/local/lib/node_modules/npm/bin/npm-cli.js:19:13
    at Object.<anonymous> (/usr/local/lib/node_modules/npm/bin/npm-cli.js:75:3)
    at Module._compile (module.js:556:32)
    at Object.Module._extensions..js (module.js:565:10)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)

I am on a mac and installed node using homebrew.

2
  • 2
    When uninstalling, you probably want to delete these too /usr/local/lib/node_modules and /usr/local/bin/npm (I'm guessing they got the wrong permissions). Sep 15, 2016 at 5:56
  • That solved it. --Thanks!
    – Dave
    Sep 15, 2016 at 6:01

2 Answers 2

15

Alexander O'Mara's comment helped me solve this. The solution:

Run brew uninstall --ignore-dependencies node to forcefully uninstall node even if there are other modules that require node.

Once this is completed, run brew uninstall --force node to remove all the versions of node on your machine, if there is more than one version running.

At last run the following commands to remove all files and install node again:

rm -rf /usr/local/lib/node_modules
rm /usr/local/bin/npm
brew install node
2
  • @Dave no luck with your suggestion too. Any other things you want us to try? Feb 9, 2017 at 23:43
  • @learnningprogramming, you need to provide some information about what your situation is and what you have already tried so far. Are you on OSX, and using homebrew? When you say "no luck with your suggestion too" - what else have you tried?
    – Dave
    Feb 14, 2017 at 17:32
1

In your Linux box;

You may need to add the following link

  1. Go to NPM installtion dir << cd ~/node-v6.9.2-linux-x64/>> (I'm using NODE Current LTS 6.9.2)

  2. look for the file npm-cli.js in lib/node_modules/npm/bin/npm-cli.js (File name can be cli.js or npm-cli.js)

  3. cd ~/node-v6.9.2-linux-x64/bin

  4. mv npm npm_old

  5. Crate a soft link in ~/node-v6.9.2-linux-x64/bin ln -s PATH-TO/npm-cli.js npm

Try npm -v

Optional if you need to update npm version pls do npm install npm@latest -g

2
  • npm-cli.js can be found here node-v6.9.2-linux-x64/lib/node_modules/npm/bin/npm-cli.js Dec 30, 2016 at 8:14
  • The original question refers to OSX, not Linux.
    – Dave
    Feb 14, 2017 at 17:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.