19

I have a Linux server that runs some virtual Machines using KVM. Host machine is a Debian derivate with kernel 2.6.32-32(-pve).

In roughly 75% of the times I run npm install, it hangs while installing modules. I ran it in silly debug level and it always hangs at the line

npm info postinstall [module name] (older npm versions)

or

npm verb unlock done using [...] (newer npm versions)

forever.

It happens in every project on the host machine and on the virtualized systems for every node and every npm version I have tested (a lot, including the newest ones (2.7.x atm)).

It also is not deterministic. Sometimes it works, sometimes not and most of the times it hangs on a different module.

On my dev machine (which is in the same network, running OS X 10.10) it works fine.

I am not behind any kind of proxy.

What could possibly be wrong here?

EDIT: For the time being I solved this problem by checking in all my dependencies as gzipped files using https://github.com/JamieMason/shrinkpack

chmanie
  • 5,016
  • 3
  • 21
  • 28
  • Do you know what particular package's post-install this is hanging on? Also what is the node version? What is the output of ~/.npmrc? Have you tried doing `npm cache clean` to remove the lock files before running npm install? – lxe Apr 06 '15 at 19:42
  • The package on which it is hanging varies. I tried a lot of node and npm versions, as well as doing a `npm cache clean`. I'm going to check the ~/.npmrc output. – chmanie May 01 '15 at 23:14
  • Just want to add that in general I found that the more the connection is stable the more the `npm install` is stable and does not get stuck, i tried with multiple versions of `npm` nothing helped only making my internet/intranet connection more stable (best wired). – Tomer Ben David Jun 20 '16 at 12:45

13 Answers13

6

I was having the same issue for several hours, and couldn't work out what the problem was. I tried re-installing everything a few times, manually installing individual modules, switching from x64 to x86 versions of NodeJS, etc, and got nowhere.

In the end, I changed networks, from WiFi over ADSL2+ [~2mbps] to 4G Hotspot [~20mbps] and it worked in 30 seconds. No idea why, since it didn't seem like a network speed issue, but it solved the problem.

Hope this helps someone else, too!

David C
  • 122
  • 5
4

I had the same problem on our Jenkins slaves based on Ubuntu, and it was solved by upgrading npm.

Default npm installed by apt-get has version 1.3.10 now, which is very old (shown by npm --version). There are at least two ways to upgrade it:

  1. Run sudo npm install -g npm command. If you want to install a specific version you can run append it at the end of command: sudo npm install -g npm@2.1.3.
  2. Or you could add NodeSource repositories using these instructions and run usual sudo apt-get update.
Bulat
  • 262
  • 5
  • 8
  • 1
    I am sorry but I already tried a lot of npm versions (including the newest ones (2.7.x)) with no luck... – chmanie Mar 31 '15 at 15:14
  • `npm install npm` feels weird, but it works... By the way, the reason for the old npm version might by that the `nodejs` package from `apt-get` is the LTS version of Node and probably uses npm from that time. – Cedric Reichenbach Mar 15 '16 at 13:23
3

I have the same problem on Windows. I deleted my npm-cache folder and reinstalled npm. Everything started working normally after that. The npm-cache folder can be found at

<your-drive>\Users\<your-name>\AppData\Roaming\npm-cache

Remember to turn on 'View hidden files because the AppData folder by default is hidden

You can reinstall npm by using the command,

npm i npm -g
Alf Moh
  • 7,159
  • 5
  • 41
  • 50
1

On Windows make sure you are in a native CMD (not in VSCODE or whatever IDE). Also, try increasing the max memory limit for node:

set NODE_OPTIONS=--max_old_space_size=8096 
FlavorScape
  • 13,301
  • 12
  • 75
  • 117
0

I did the same, switched my network from WiFi to 3G and it worked.

0

I'm experiencing the same problem, this is the issue on Github: https://github.com/npm/npm/issues/7862

There are some useful tips that seemed to help a few people.

For me doing $ npm install -g node-gyp (as suggested here: http://gangmax.me/blog/2013/05/13/resolve-npm-update-node-gyp-hung-problem/) fixed the problem.

fabio.sussetto
  • 6,964
  • 3
  • 25
  • 37
0

I had the same problem and just run

npm cache clean

And it works!

JC Teo
  • 221
  • 2
  • 5
0

Had this same problem in Windows. The solution was to restart after installing node and npm and then run command prompt as administrator.

Jeff Davis
  • 4,736
  • 4
  • 38
  • 44
0

In my case, a system restart did the work. I ran npm install --verbose which suggested some lock on a file in npm-cache. And I think the system released the file (which was under use) after the system restart. I am using windows.

Prashant naik
  • 567
  • 1
  • 4
  • 14
0

Try cloning the project again and then run npm install to install the packages in your terminal.

Tyler2P
  • 2,324
  • 26
  • 22
  • 31
Ashish Kumar
  • 29
  • 1
  • 5
0

I ran into this with npm v6, and it turned out I was just being impatient. I just needed to wait a little longer and it proceeded to the next step.

Matt Sgarlata
  • 1,761
  • 1
  • 16
  • 13
0
npm cache clean --force 

works for me :)

-1

=> this method working with me When npm block in installation Package for IONIC installation and ReactNative and another package npm.

you can change temporary : npm config set prefix C:\Users[username]\AppData\Roaming\npm\node_modules2

  • change the Path in Environment Variables set C:\Users[username]\AppData\Roaming\npm\node_modules2

  • Run the your command to install your package .

  • open file explorer copy the link C:\Users[username]\AppData\Roaming\npm\node_modules

    ok file yourpackage.CMD created another folder Created "node_modules2" in node_modules and contain your package folder.

  • copy your package file CMD to parent folder "npm"

  • copy your package folder to parent folder "node_modules"

  • now run npm config set prefix C:\Users[username]\AppData\Roaming\npm

  • change the Path in Environment Variables set C:\Users[username]\AppData\Roaming\npm

  • now package working correctly with Command line

  • Maybe you could try to format it a bit better, and add some more in-depth details about the procedure you mention? – Paradox Mar 26 '19 at 23:59