npm update -g has broken npm #4099

Closed
KingScooty opened this Issue Nov 6, 2013 · 55 comments

Projects

None yet
@KingScooty

I've just run a routine npm update -g. Things were going well until i got this error:

/usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js
npm ERR! Error: ENOENT, chmod '/usr/local/lib/node_modules/npm/node_modules/ansi/examples/imgcat/index.js'
npm ERR! If you need help, you may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <npm-@googlegroups.com>

npm ERR! System Darwin 13.0.0
npm ERR! command "node" "/usr/local/bin/npm" "update" "-g"
npm ERR! cwd /Users/KingScooty/Sites/wildflame/bbc/sport/live
npm ERR! node -v v0.10.13
npm ERR! npm -v 1.3.11
npm ERR! path /usr/local/lib/node_modules/npm/node_modules/ansi/examples/imgcat/index.js
npm ERR! code ENOENT
npm ERR! errno 34
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/KingScooty/Sites/wildflame/bbc/sport/live/npm-debug.log
npm ERR! not ok code 0

And now npm seems to be broken. Running npm results in:

$ npm
-bash: /usr/local/bin/npm: No such file or directory

What's happened?

Jobbies commented Nov 7, 2013

Exactly the same thing has happened to me too.

It's happened a few times before, and it's quite annoying!
I'm hoping there's either a fix, or an easier way to sort it than just reinstalling node.

rsf2 commented Nov 7, 2013

Exact same issue here too.

Also have a look at #4046.

For me it seems the issue was that I was starting the update from some random dir and not ~/

What I did was:

  • Reinstall npm while being in ~/:

    curl http://npmjs.org/install.sh | sh

  • After that I also tried npm update -g again but this time while being in ~/ and everything worked great now.

Hope this works for you too.

No luck :/

Ran npm update -g from ~/ and it gets so far, before breaking again:

/usr/local/bin/learnyounode -> /usr/local/lib/node_modules/learnyounode/learnyounode.js
learnyounode@0.2.16 /usr/local/lib/node_modules/learnyounode
├── duplexer@0.1.1
├── through@2.3.4
├── boganipsum@0.1.0
├── hyperquest@0.1.8 (through@2.2.7)
├── bl@0.4.2 (readable-stream@1.0.17)
├── concat-stream@1.0.1 (bops@0.0.6)
├── through2-map@1.1.0 (through2@0.1.0)
└── workshopper@0.3.3 (map-async@0.1.1, tuple-stream@0.0.2, split@0.2.10, mkdirp@0.3.5, colors-tmpl@0.1.0, xtend@2.1.1, terminal-menu@0.1.0, optimist@0.6.0, pygmentize-bundled@2.1.0)
npm ERR! error rolling back Error: EACCES, unlink '/usr/local/lib/node_modules/npm/.npmignore'
npm ERR! error rolling back  npm@1.3.14 { [Error: EACCES, unlink '/usr/local/lib/node_modules/npm/.npmignore']
npm ERR! error rolling back   errno: 3,
npm ERR! error rolling back   code: 'EACCES',
npm ERR! error rolling back   path: '/usr/local/lib/node_modules/npm/.npmignore' }
npm ERR! Error: EACCES, unlink '/usr/local/lib/node_modules/npm/.npmignore'
npm ERR!  { [Error: EACCES, unlink '/usr/local/lib/node_modules/npm/.npmignore']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/usr/local/lib/node_modules/npm/.npmignore' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

npm ERR! System Darwin 13.0.0
npm ERR! command "node" "/usr/local/bin/npm" "update" "-g"
npm ERR! cwd /Users/KingScooty
npm ERR! node -v v0.10.21
npm ERR! npm -v 1.3.11
npm ERR! path /usr/local/lib/node_modules/npm/.npmignore
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, unlink '/usr/local/lib/node_modules/npm/.npmignore'
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/KingScooty/npm-debug.log
npm ERR! not ok code 0
KingScooty at Scotty's MacBook Air in ~
$ npm
-bash: /usr/local/bin/npm: No such file or directory

exactly the same issue here !

mrzmyr commented Jan 7, 2014

I solved it by using sh with sudo:
curl https://npmjs.org/install.sh | sudo sh

Member
timoxley commented Jan 8, 2014

I can confirm this is still an issue today.

Easiest way to reproduce, try install a different version of npm via npm, and kill it before it's done:

> npm install -g npm@1.1.25
npm http GET https://registry.npmjs.org/npm/1.1.25
npm http 304 https://registry.npmjs.org/npm/1.1.25
npm WARN engine npm@1.1.25: wanted: {"node":"0.6 || 0.7 || 0.8","npm":"1"} (current: {"node":"v0.10.24","npm":"1.3.23"})
npm WARN package.json node-uuid@1.3.3 No repository field.
npm http GET https://registry.npmjs.org/npm-registry-client
^C%
> npm
zsh: command not found: npm

I have this problem because I use sudo npm install now I can't npm update or npm update -g
also tried sudo chown -R username: ~/.npm but that didn't work.
It says Please try running this command as root/Admin
here is the gist

Member
timoxley commented Jan 8, 2014

@anthonybrown hm, I don't know really but it looks like perhaps your npm modules aren't in ~/.npm, rather they are in /Users/anthonybrown/node_modules. Maybe try chowning that folder, but ideally, just clean it all out and reinstall via https://gist.github.com/isaacs/579814 or isaacs/nave

Member
timoxley commented Jan 8, 2014

@anthonybrown also, this issue is more about npm destroying itself if it fails to update itself, you seem to have a local configuration error due to that sudo, which might not be considered npm's responsibility?

@timoxley okay I will try that.
I had a moment when I used sudo with npm lol
Thanks

Today I was tearing my hairs out until I remembered that I always run sudo npm update -g or sudo npm install -g.
On Ubuntu, running sudo chown -R $USER /usr/local/lib/node_modules fixed my problem.


Edit: I'm currently using nvm and it's amazing. No more sudo-ing for global installs 😄

JGarrido commented Feb 6, 2014

👍 to getting this resolved

chown'ing /usr/local worked here, sergiolepore. thank you

@millerized you're welcome

Zenwolf commented Mar 19, 2014

I installed node.js using the official Mac OS X installer node-v0.10.26.pkg, and this problem happens whenever I run npm update -g. I end up having to reinstall Node.js every time because NPM is removed. I was under the impression that I should never have to use sudo or grant elevated permission on specific directories just to update packages.

npm http GET https://registry.npmjs.org/npm
npm http 200 https://registry.npmjs.org/npm
npm http GET https://registry.npmjs.org/npm/1.4.6
npm http 200 https://registry.npmjs.org/npm/1.4.6
npm http GET https://registry.npmjs.org/npm/-/npm-1.4.6.tgz
npm http 200 https://registry.npmjs.org/npm/-/npm-1.4.6.tgz
npm ERR! error rolling back Error: EACCES, unlink '/usr/local/lib/node_modules/npm'
npm ERR! error rolling back  npm@1.4.6 { [Error: EACCES, unlink '/usr/local/lib/node_modules/npm']
npm ERR! error rolling back   errno: 3,
npm ERR! error rolling back   code: 'EACCES',
npm ERR! error rolling back   path: '/usr/local/lib/node_modules/npm' }
npm ERR! Error: EACCES, unlink '/usr/local/lib/node_modules/npm'
npm ERR!  { [Error: EACCES, unlink '/usr/local/lib/node_modules/npm']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/usr/local/lib/node_modules/npm' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.

npm ERR! System Darwin 12.5.0
npm ERR! command "node" "/usr/local/bin/npm" "update" "-g"
npm ERR! cwd /Users/mjaquish
npm ERR! node -v v0.10.26
npm ERR! npm -v 1.4.3
npm ERR! path /usr/local/lib/node_modules/npm
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, unlink '/usr/local/lib/node_modules/npm'
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/mjaquish/npm-debug.log
npm ERR! not ok code 0
monsur commented May 3, 2014

This still happens. "npm update" works fine, but "npm update -g" gives the same error that others are having, and uninstalls npm.

I needed the -L to follow the redirect:
curl -L http://npmjs.org/install.sh | sudo sh

janusch commented May 9, 2014

👍 @metaraine this command did it for me! Stooped first around by reading this issue from top to bottom...

@metaraine, I tried this but got: Could not resolve host: www.npmjs.org

@firecentaur I double checked it and it still works. I'm not sure why you'd get a "cannot resolve host" error unless there was a networking error.

I'm still getting errors, do I need to reinstall all the global packages with npm install -g

npm -v 1.4.13

errors are gone, and I didn't have to use sudo

Member

👍

@timoxley timoxley closed this Jun 21, 2014
Contributor
mhart commented Jun 30, 2014

I just got this error and the npm command is no longer available.

$ npm update -g
...
/usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js
npm ERR! Error: ENOENT, chmod '/usr/local/lib/node_modules/npm/node_modules/ansi/examples/starwars.js'
npm ERR! If you need help, you may report this *entire* log,
npm ERR! including the npm and node versions, at:
npm ERR!     <http://github.com/npm/npm/issues>

npm ERR! System Darwin 13.2.0
npm ERR! command "/usr/local/bin/node" "/usr/local/bin/npm" "update" "-g"
npm ERR! cwd /Users/michael/github/aws-sdk-js
npm ERR! node -v v0.10.29
npm ERR! npm -v 1.4.14
npm ERR! path /usr/local/lib/node_modules/npm/node_modules/ansi/examples/starwars.js
npm ERR! code ENOENT
npm ERR! errno 34
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/michael/npm-debug.log
npm ERR! not ok code 0
$ npm outdated -g
-bash: /usr/local/bin/npm: No such file or directory
mhulse commented Jul 14, 2014

Same thing (-bash: /usr/local/bin/npm: No such file or directory) just happened to me (I was not in home dir when running npm update -g). Last Friday, the same thing happened to my co-worker's machine. Anyway, since this issue looks active, +1 for following it. Any reason why not being in my home directory when running npm update -g is a problem (or, is it just a coincidence)?

mhulse commented Jul 14, 2014

FYI to future readers: Following these instructions got me back up and running again (i.e., complete uninstall/re-install of node, which comes with npm).

Using the flag -L suggested by @metaraine worked for me. I then successfully used sudo npm update -g from the home directory.

Still an issue: npm update -g caused me to lose npm

Contributor
stevemao commented Aug 5, 2014

Happens to me too.

and to me!

vinch commented Aug 8, 2014

Same here.

same here. i think its a permissions bug. i deleted the entire /usr/lib64/node_modules folder and after that i can now install the global packages again and update them using "npm update -g" without things going wrong.

(the folder may be different in your distro)

baird commented Aug 12, 2014

+1 - didn't sudo, not in home dir when issued

I resolve that using (curl https://www.npmjs.org/install.sh | sh) or (curl https://www.npmjs.org/install.sh | sudo sh) in home dir (~). 👍

mhulse commented Aug 12, 2014

I resolve that using (curl https://www.npmjs.org/install.sh | sh) or (curl https://www.npmjs.org/install.sh | sudo sh) in home dir (~). 👍

Interesting. To clarify, you're saying you run (basically) cd; curl https://www.npmjs.org/install.sh | sh?

Potentially stupid questions: Could the npm update -g do the checking for "if in home dir" bit? In other words, how could npm update -g be ran without causing probs if not in home dir?

but my problem was because I use brew for install other thing! and npm disappear i dont know why! so i found that to solve my problem!

lahvey commented Sep 3, 2014

On Mac, I can reproduce:

  • Install node.pkg from nodejs.org. It will ask for root permission.
  • Run npm update -g, there should be many EACCES errors: Error: EACCES, unlink '/usr/local/lib/node_modules/...
  • Run npm or npm update -g again, you will get bash: /usr/local/bin/npm: No such file or directory

After searching stackoverflow, I found it's node install permission issue. Once you install node with root, you will get endless trouble.
So, first you should remove all node installations @mhulse.
(http://stackoverflow.com/a/11178106)
And then install nvm for development.
(http://stackoverflow.com/a/24404451)

mhulse commented Sep 3, 2014

Thanks for tips @lahvey, I did not realize there was a nvm. That's cool, checking it out now. 👍

jskye commented Sep 11, 2014

this happened to me as well (mac, mavericks)
@metaraine's curl -L http://npmjs.org/install.sh | sudo sh worked for me.
The from home, "npm update -g" still didnt work but doesnt break.
But sudo npm update -g from home works, tho, not without unmet dependencies and at least one uncaught exception.

@metaraine's curl -L http://npmjs.org/install.sh | sudo sh did it for me as well 👍

This is typical and somewhat unexpected behavior of NPM but a fix is coming: #6247

Was having the same issue with Node being installed, but NPM not being found. The following worked for me like a charm:

 - curl -L http://npmjs.org/install.sh | sudo sh
@othiym23 othiym23 added the support label Dec 5, 2014

This works for me on openSuse

curl -L http://npmjs.org/install.sh | sudo sh

Still an issue.

webjay commented Dec 26, 2014

This housecleaning worked for me:

mv /usr/local/lib/node_modules /tmp
rm -rf /tmp/node_modules/npm
curl https://www.npmjs.com/install.sh | sh
npm cache clean
npm install -g $(ls -1rt /tmp/node_modules/)

The command rm -rf /tmp/node_modules/[package] can be used to remove what might be causing problems or no longer needed.

thank you @webjay your solution worked for me!

@k-j-kleist k-j-kleist referenced this issue in zurb/foundation-apps Jan 18, 2015
Closed

foundation-apps build fails #375

gaearon commented Jan 19, 2015

Still an issue. It's so frustrating.

wiesson commented Feb 7, 2015

I still have this error after updating to node 1.20

curl -L http://npmjs.org/install.sh | sudo sh and
sudo chown -R $USER /usr/local/lib/node_modules did the trick for me (executed from my homefolder).

This answer on StackOverflow helped me to solve the problem comparing to everything mentioned above in this discussion. I have just uninstalled both node and npm and installed again with .pkg file downloaded directly from http://nodejs.org.

NicoleB commented Mar 23, 2015

Ran npm update today. Then immediately ran npm update -g npm per Grunt's instructions to ensure latest npm update, and now npm is nowhere to be found. This issue really needs to get sorted out (it's been persisting since 2013).

Thanks @manakor for posting a workaround. Echoing comments from that link, Node should at least write some sort of built-in clean-up tool to make a clean reinstallation of npm less of a hassle.

I run curl -L http://npmjs.org/install.sh | sudo sh and it works!

However, can anyone tell me why it works? What happens inside the code?

kokarn commented Apr 20, 2015

I'll just +1 this as well, still an issue

Owner
iarna commented Apr 20, 2015

This was fixed in npm@2.7.1 with 6de1e91. Of course, if you're currently using an older version of npm you can't safely use its npm update to update to a current version of npm. Use npm install -g npm instead.

I'm going to lock this issue as further discussion here is not helpful.

If you DO encounter this problem with an npm >= 2.7.1, please open a new issue.

@iarna iarna locked and limited conversation to collaborators Apr 20, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.