Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm: module.js:457 throw err; Error: Cannot find module 'npmlog' on a mac using brew

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.

like image 843
Dave Avatar asked Sep 15 '16 05:09

Dave


2 Answers

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
like image 96
Dave Avatar answered Nov 08 '22 00:11

Dave


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

like image 1
user7296279 Avatar answered Nov 08 '22 02:11

user7296279