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.
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
In your Linux box;
You may need to add the following link
Go to NPM installtion dir << cd ~/node-v6.9.2-linux-x64/>> (I'm using NODE Current LTS 6.9.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)
cd ~/node-v6.9.2-linux-x64/bin
mv npm npm_old
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With