npm hangs on postinstall / unlock
Asked Answered
E

13

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

Elude answered 11/3, 2015 at 12:7 Comment(3)
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?Grinder
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.Elude
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).Coca
C
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!

Christianachristiane answered 3/5, 2015 at 2:24 Comment(1)
I can confirm that. Changing from wifi to lan worked. Thanks! :)Zingale
C
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 [email protected].
  2. Or you could add NodeSource repositories using these instructions and run usual sudo apt-get update.
Crosswise answered 31/3, 2015 at 12:19 Comment(2)
I am sorry but I already tried a lot of npm versions (including the newest ones (2.7.x)) with no luck...Elude
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.Vergeboard
K
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
Kirkwall answered 18/9, 2017 at 3:51 Comment(1)
Reinstalling npm worked for me, thanks!Vorster
T
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 
Teena answered 21/1, 2020 at 22:19 Comment(0)
B
0

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

Bough answered 6/6, 2015 at 3:37 Comment(0)
R
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.

Ravish answered 16/9, 2015 at 11:20 Comment(0)
P
0

I had the same problem and just run

npm cache clean

And it works!

Paranoid answered 6/9, 2018 at 23:56 Comment(0)
H
0

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

Homosporous answered 20/12, 2018 at 3:20 Comment(0)
S
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.

Secondbest answered 6/12, 2021 at 16:30 Comment(0)
O
0

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

Ordinarily answered 31/1, 2022 at 6:42 Comment(2)
npm cache clean --force. this also you can tryOrdinarily
or change your network might be internet issueOrdinarily
C
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.

Collard answered 7/4, 2022 at 13:8 Comment(0)
C
0
npm cache clean --force 

works for me :)

Clementia answered 18/11, 2022 at 4:51 Comment(0)
B
-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

Bathelda answered 26/3, 2019 at 23:7 Comment(1)
Maybe you could try to format it a bit better, and add some more in-depth details about the procedure you mention?Mozellemozes

© 2022 - 2024 — McMap. All rights reserved.