简体   繁体   中英

npm hangs on postinstall / unlock

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

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!

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 .

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

我做了同样的事情,将我的网络从 WiFi 切换到 3G 并且它工作正常。

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.

I had the same problem and just run

npm cache clean

And it works!

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

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 

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.

再次尝试克隆项目并执行 npm i

"

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.

npm cache clean --force 

works for me:)

=> 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM