21

I have NVM 0.30.1 and used it to install node.js v5.4.0 (with NPM 3.5.4) on Fedora 22. When I run npm update -g, I receive the following warnings:

npm WARN EBUNDLEOVERRIDE Replacing bundled npm > init-package-json with new installed version
npm WARN EBUNDLEOVERRIDE Replacing bundled npm > node-gyp with new installed version
npm WARN EBUNDLEOVERRIDE Replacing bundled npm > npm-install-checks with new installed version
npm WARN EBUNDLEOVERRIDE Replacing bundled npm > npmlog with new installed version
npm WARN EBUNDLEOVERRIDE Replacing bundled npm > read-package-json with new installed version

And after that, when I run npm I get this error:

module.js:328
    throw err;
    ^

Error: Cannot find module 'npmlog'
    at Function.Module._resolveFilename (module.js:326:15)
    at Function.Module._load (module.js:277:25)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at /home/peflorencio/.nvm/versions/node/v5.4.0/lib/node_modules/npm/bin/npm-cli.js:20:13
    at Object.<anonymous> (/home/peflorencio/.nvm/versions/node/v5.4.0/lib/node_modules/npm/bin/npm-cli.js:76:3)
    at Module._compile (module.js:398:26)
    at Object.Module._extensions..js (module.js:405:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)

Does anyone know what it is and how to solve it?

Thanks

peflorencio
  • 2,284
  • 2
  • 32
  • 40

9 Answers9

7

What fixed this for me was

sudo rm -rf /usr/local/lib/node_modules/

and then re-installing node (with npm).

Alan H.
  • 16,219
  • 17
  • 80
  • 113
  • This doesn't work... How do you install things using npm if you just blatted it? `#!/bin/bash -eo pipefail sudo rm -rf /usr/local/lib/node_modules/ sudo npm install -g npm@latest sudo: npm: command not found Exited with code 1` – Antony Jones Oct 23 '17 at 15:31
  • @antony Re-install node itself! IIRC, I did this via the installer downloadable from the official node website – Alan H. Sep 23 '18 at 01:49
6

Thanks for the answers. It was a bug and it has already been fixed in Node v5.4.1. Now it's working as usual.

peflorencio
  • 2,284
  • 2
  • 32
  • 40
4

It looks like npm update -g cannot update npm to the newest version. I solve the problem by updating npm installation manually.

  1. Install/ reinstall node to get the bundled npm
  2. run npm install -g npm@3.5.4 to update the global npm installation
  3. now npm update -g should work
motou
  • 726
  • 4
  • 12
  • please try "curl -0 -L http://npmjs.org/install.sh | sudo sh" for the 2nd step to see if it helps. – motou Jan 13 '16 at 12:52
  • working for root : # npm -v 3.10.10 but not for jenkins user : jenkins@ip-172-31-22-20:~$ npm -v module.js:471 throw err; ^ – Ashish Karpe Sep 07 '17 at 13:06
  • Error: Cannot find module 'npmlog' at Function.Module._resolveFilename (module.js:469:15) at Function.Module._load (module.js:417:25) at Module.require (module.js:497:17) at require (internal/module.js:20:19) at /usr/local/bin/npm:19:13 at Object. (/usr/local/bin/npm:75:3) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) – Ashish Karpe Sep 07 '17 at 13:06
  • jenkins@ip-172-31-22-20:~$ node -v v6.11.1 – Ashish Karpe Sep 07 '17 at 13:09
3

I have faced the same issue in my Windows 10 PC. After looking into solutions, since i couldn't find the exact solution for the issue i was facing Cannot find module 'npmlog' I just uninstalled the node js and then, deleted both 'npm' and 'npm-cache' in "C:\Users\YourPCName\AppData\Roaming"

Then, i downloaded the latest version of node from Node JS Website

And, installed node js

After that i checked with the path in environment variables.

Finally run the command prompt 'run as administrator' and npm install npm -g

Checking your version will show the latest version. 'npm -v'

I got the latest version - v3.10.9

Try this. this should work.

Saiyaff Farouk
  • 5,103
  • 4
  • 24
  • 38
2

If people with linux are facing the problem, here is the solution:

As of the date of this post, the NPM version packaged with Nodejs doesn't work. If you installed this package, run

sudo rm -rf /usr/local/bin/npm
sudo apt-get install node
sudo mv /usr/bin/npm /usr/local/bin/npm

New version should be 3.10.8 and the old error gone

hithere
  • 21
  • 1
1

init-package-json, node-gyp, npm-install-checks, npmlog, read-package-json didn't installed correctly. Not sure why though.

Didn't find the root cause for the issue but I used the hacky way to install the packages above for now:

  • Roll back to the previous node version which npm didn't be updated. For example, nvm use iojs
  • cd to where npm installed, for example, cd /home/peflorencio/.nvm/versions/node/v5.4.0/lib/node_modules/npm and reinstall those packages like rm -rf node_modules/init-package-json && npm install init-package-json etc.
Yujun Wu
  • 2,992
  • 11
  • 40
  • 56
0

Some of the answers already answered the question, but I will still like to throw in my own idea. I encountered same issue after I was told to run npm update -g npm after running that piece of code, the error started. I solved mine by using Node Version Manager(nvm):

nvm install 8

Note: not actually 8, but to a version of your choice e.g(6,5). Writing the version number will automatically install the stable of the version specified. After the installation you should get a CLI message:

Now using node v8.11.4 (npm v5.6.0) 
Fillipo Sniper
  • 419
  • 2
  • 11
  • 28
0

If you're using a Mac, perform the following steps, to remedy (assuming you have Homebrew installed already):

sudo rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/npm*

(to overcome bash: /usr/local/bin/npm: No such file or directory error):

hash -r 

Then go ahead with updating brew (to keep its kegs up to date) and the reinstallation process, linking is optional.

brew update

brew reinstall node

brew link --overwrite node

At any point inbetween you can use npm -v or node -v to test whether or not you are making progress. If you have node returning a version, but not npm then you will need to add your path to your environment with:

export PATH="/usr/local/bin:$PATH"
Grant
  • 5,709
  • 2
  • 38
  • 50
  • Don't forget to run `npm rebuild` inside of your projects, after this sort of upgrade takes place, as it will update the C++ binaries – Grant Nov 28 '19 at 01:52
0

There is an option to bump npm without reinstalling node.

#### # this will remove current npm
rm -rf /usr/local/lib/node_modules/npm/

#### # install npm from sources. Version 3.5.x will be installed
apt-get update
apt-get install npm

#### # install the newest npm version. Bumping from 3.5.X to 6.14.X goes without any issue :)
/usr/bin/npm install npm@latest -g

#### # additionally, npm with version 3.5.x is not added to $PATH, so it's not used.
David Buck
  • 3,752
  • 35
  • 31
  • 35