user1090227
user1090227

Reputation: 1901

npm install hangs

This is my package.json:

{
"name": "my-example-app",
"version": "0.1.0",
"dependencies": {

  "request": "*",
  "nano": "3.3.x",
  "async": "~0.2"
  }
}

Now, when I open the cmd and run npm install, the install hangs. What am I doing wrong?

Upvotes: 189

Views: 430116

Answers (30)

Dan Dascalescu
Dan Dascalescu

Reputation: 151916

As of November 2024, a known issue with Node/npm is causing npm install to apparently hang/freeze at some point.

https://github.com/npm/cli/issues/7814#issuecomment-2453541806

(not pasting the solution since this will hopefully become irrelevant well before the link rots).

Upvotes: 10

oneimperfectguy
oneimperfectguy

Reputation: 959

Most probable the issue is with the internet or package versions mismatch. Try these two things.

  1. Turn off the wifi and turn on again on your laptop and connect with your wifi. If you are connected via ethernet, unplug the cable and plug again. Try npm i now and see if it worked.
  2. If not, delete the package-lock.json that is in the root folder and then run npm i.

For me, turning the wifi off and on on my device resolved the issue.

Upvotes: -1

Haseeb
Haseeb

Reputation: 990

I just rebooted the machine and everything works well.

$ sudo reboot

Upvotes: -3

Dr BDO Adams
Dr BDO Adams

Reputation: 395

In my case IPv6 connection to the registry where not working on ubuntu

I did

nslookup registry.npmjs.org

Picked a couple of IpV4 addresses

and added them to /etc/hosts

e.g.

registry.npmjs.org  104.16.30.34  104.16.29.34

And npm started working for me.

Upvotes: 1

Simon Edwards
Simon Edwards

Reputation: 33

For me it was Nord VPN client that caused the issue. Even though the vpn client wasn't connected it had for some reason got itself in a twist.

Restarting the Nord VPN Windows services didn't work, only a full reboot :-(

What prompted me to look at this was

  1. npm i - took and age to run
  2. Failed to download Inter from Google Fonts. Using fallback font instead.
  3. TypeError: fetch failed at node:internal/deps/undici/undici:12443:11, cause: ConnectTimeoutError: Connect Timeout Error

Upvotes: 2

k-lusine
k-lusine

Reputation: 467

I tried almost every method described in the answers, they didn't work for me. Initially I was using the integrated terminal inside VSCode. I ran the same command in the native terminal instead, and it worked!

Hope this will help someone

Upvotes: 1

Mahmood Hussain
Mahmood Hussain

Reputation: 501

Surprisingly just restarting my computer and running npm install again worked for me

Upvotes: 10

Marinos An
Marinos An

Reputation: 10818

In my case it was freezing while calling reify.

I downgraded from node 16 to node 14 and everything worked perfectly.

Upvotes: 1

Caleb Koch
Caleb Koch

Reputation: 874

npm cache clear --force has fixed this issue for me in the past.

Furthermore, when running npm install on an air-gapped network (by the way, I provide a description about how to do this with Verdaccio), I had an issue where the install would hang at the very end. Turning off auditing (i.e. npm set audit false) on the machine on the air-gapped network resolved this issue.

Upvotes: 20

Lalith Yagnavalkya
Lalith Yagnavalkya

Reputation: 149

Mine was hanging when I was trying to install latest version of react-router-dom, I just stopped server from running and then tried installing and it worked.

Upvotes: 0

konradz
konradz

Reputation: 51

I had same issue when installing legacy version of vue tools (4.1.5).

Downgrading node to node 10 worked for me.

Upvotes: -1

Ciaran Gallagher
Ciaran Gallagher

Reputation: 4020

In case anyone else encounters this, I left the npm install to run for long enough, and then the Jest extension crashed (v4.2.1), at which point the npm install completed successfully.

The Jest configuration seems to show that a test auto-watch feature was enabled. I haven't changed any Jest settings as far as I'm aware, so this must be out-of-the-box functionality.

Upvotes: 0

Kimberly Aguilar
Kimberly Aguilar

Reputation: 93

Remove node_modules & package-lock.json from previous npm install and install again

rm -rf node_modules package-lock.json
npm install

or

If npm install loader is stuck and then pops up with..

npm ERR! code UNABLE_TO_GET_ISSUER_CERT_LOCALLY

npm ERR! errno UNABLE_TO_GET_ISSUER_CERT_LOCALLY

npm ERR! request to https://registry.npmjs.org/jest failed, reason: unable to get local issuer certificate"

then,

npm config set strict-ssl false
npm install

or

Follow to uninstall Node.js and install properly

https://www.geeksforgeeks.org/how-to-completely-remove-node-js-from-windows/

https://coding-boot-camp.github.io/full-stack/nodejs/how-to-install-nodejs

I personally had this issue and did all the steps I listed above. My issue was fixed with npm config set strict-ssl false

Upvotes: 9

Lucas Basquerotto
Lucas Basquerotto

Reputation: 8031

I was having this error because I was running npm in a (docker) container in WSL2, and docker in WSL2 was configuring the wrong nameservers in the containers, making the container unable to resolve hosts.

To see if your container (or even your host) can resolve hosts, you can try running: curl https://github.com. In my case I received curl: (6) Could not resolve host: github.com.

The error in the docker container doesn't happen if I don't use the default bridge, instead I used a custom bridge and defined the container with it, in which case the resolv.conf file ends up with the correct nameserver:

$ cat /etc/resolv.conf 
nameserver 127.0.0.11
options ndots:0

The ip 127.0.0.11 corresponds to the docker DNS server, solving the problem in my case.

If you aren't running npm in a container, your issue may still be related to some misconfigured resolv.conf file (if you are in a Linux machine, or in Windows with WSL/WSL2).

Upvotes: 0

cujo30227
cujo30227

Reputation: 770

On MacOS, I was able to solve this by

networksetup -setv6off Wi-Fi

After installing, you can revert to the original configuration with

networksetup -setv6automatic Wi-Fi

Upvotes: 24

Joel Sullivan
Joel Sullivan

Reputation: 1745

I've hit this problem a couple times.

  1. When I was on VPN, I pressed Ctrl-C and disconnected from the VPN. Then npm install worked.
  2. When I wasn't on VPN, I pressed Ctrl-C and connected to the VPN. Then, again, npm install worked.

Upvotes: 2

demo7up
demo7up

Reputation: 578

It was strange but I guess I was just being impatient ran -> npm install --verbose and saw there was progress but it was just really slow!!! All I needed was patience :D

Upvotes: 9

Sebs030
Sebs030

Reputation: 616

On windows i suddenly had the same issue and tried all of the above, but the final solution for me was to switch off the ransomware protection which I had activated. It somehow doesn´t go well along with npm enter image description here

Upvotes: 2

novice2ninja
novice2ninja

Reputation: 471

With due respect to all the answers, I switched to a different network and it worked for me.

Upvotes: 2

Vinu
Vinu

Reputation: 89

I had npm hanging on installation of electronjs on Windows 10. I reinstalled and still it was hanging. But I noticed it got installed on another desktop in the same network. So finally I found the culprit. The issue was caused by Bitdefender free edition. There was no warning by the antivirus but it was blocking it silently. Even the console was not closing once the installation starts as it kept hanging. Disable antivirus/firewall if its on Windows and make sure network is open as npm does not seem to have a proper way of communicating network blocks and will keep proceeding indefinitely.

Upvotes: 1

Greg0ry
Greg0ry

Reputation: 1069

In my case npm install was hanging because it was waiting for me to input a password to my ssh key while cloning from git repository. There was no prompt and I realized this might be the case when I typed random character and nothing was echoed back. In my case I had to look at package.json file and clone locally repositories listed there. Then I updated package.json and changed paths of those git repositories to my local paths. After doing this everything else was installed without further errors.

Upvotes: 1

john grad
john grad

Reputation: 141

Uninstalling and installing node and npm worked for me. I'm using Ubuntu 20.04.1 LTS

Upvotes: 0

user12055579
user12055579

Reputation: 762

Updating npm helped me on Mac OS. Use the command:

sudo npm install -g npm@latest

Upvotes: 11

idan.bel
idan.bel

Reputation: 29

install nvm (Node Version Manager) and downgrade node version from 14 to 12 solved the issue in my case

Upvotes: 1

Francesco Borzi
Francesco Borzi

Reputation: 61724

I had the same issue on macOS, after some time struggling and searching around, this answer actually solved the issue for me:

npm config rm proxy
npm config rm https-proxy
npm config set registry http://registry.npmjs.org/

Upvotes: 23

Jeff Ward
Jeff Ward

Reputation: 18986

Check your .npmrc file for a registry entry (which identifies a server acting as a package cache.)

For me, npm install would hang partway through, and it was because of a old / non-responsive server listed in my .npmrc file. Remove the line or comment it out:

>cat ~/.npmrc
#registry=http://oldserver:4873

(And/or check with your IT / project lead as to why it's not working ;)

Upvotes: 0

Pier-Luc Gendreau
Pier-Luc Gendreau

Reputation: 13814

While your mileage may vary, running npm cache verify fixed the issue for me.

Upvotes: 12

michael
michael

Reputation: 682

When your ssh key is password protected run ssh-add. npm probably hangs somewhere asking for your password.

Upvotes: 6

SUSHIL MANKAR
SUSHIL MANKAR

Reputation: 9

I just turn off my windows firewall and it worked for me. You can also try different versions of npm.

Upvotes: 0

Chandni Agarwal
Chandni Agarwal

Reputation: 1

check your environment variables for http and https

The existing entries might be creating some issues. Try deleting those entries.

Run "npm install" again.

Upvotes: -1

Related Questions