177

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?

14
  • 6
    Where does it hang? Before any output?
    – Ry-
    Commented Jun 1, 2013 at 14:58
  • 1
    Please post the output that you see when you run npm install. Commented Jun 1, 2013 at 15:00
  • 57
    Try npm install --verbose and see if you can find anything.
    – Dogbert
    Commented Jun 1, 2013 at 15:00
  • 2
    How long did you wait? npm is really slow in general. :)
    – Ry-
    Commented Jun 1, 2013 at 15:05
  • 1
    Just give it some time, it will be done. Commented May 22, 2022 at 14:24

38 Answers 38

234

I had the same problem. The reason - wrong proxy was configured and because of that npm was unable to download packages.

So your best bet is to the see the output of

$ npm install --verbose

and identify the problem. If you have never configured proxy, then possible causes can be

  • Very outdated npm version.
  • Some problem with your internet connection.
  • Permissions are not sufficient for npm to modify files.
7
  • 15
    npm config set loglevel info and then run npm i again
    – gcb
    Commented Apr 1, 2016 at 7:00
  • npm ls --global --parseable --long --loglevel info Commented Mar 10, 2018 at 2:35
  • I made multiple iterations rerunning npm install --verbose, deleting the file at latest log path shown before a hang up. Finally installation came up to the end.
    – Zon
    Commented Aug 21, 2018 at 5:13
  • 2
    This fixed it for me. I was installing webpack on OS X and it hung during the install process. I gave it time, then finally killed it. I ran npm install --versbose (following your advice) and then reran the webpack install. All is well! Commented Dec 19, 2018 at 18:06
  • Installing yarn globally using npm then running yarn install fixed this for me (also yarn logs "There appears to be trouble with your network connection. Retrying..." but at least it does not hang and continues till Done in 1035s. is logged).
    – Top-Master
    Commented Dec 8, 2020 at 6:20
67

You can try deleting package-lock.json and running npm install afterwards. This worked for me.

6
  • Where can I find this package? Commented May 5, 2020 at 9:54
  • 1
    This file you can found in root of project.. same level of package.json. Commented Jun 12, 2020 at 19:25
  • 4
    my npm install would get stuck on the same package every time (on both machines even). I removed the package-lock.json as well as the node_modules directory (just to be sure) and finally it worked :)
    – xorinzor
    Commented Dec 4, 2020 at 22:30
  • A fair warning to those reading this, sometimes your project becomes reliant on your package-lock.json being in a certain state so this could cause unforeseen problems by importing different package versions. Commented Jun 2, 2022 at 20:04
  • I tried about a dozen things and this is the only one that worked
    – mjr
    Commented Feb 18, 2023 at 20:26
59

I was having the same problem. I tried a

npm config set registry http://registry.npmjs.org/

to turn off https. I also tried

npm set progress=false 

to turn off the progress bar (it has been reported to slow down downloads).

The problem was with my network driver. I just needed to reboot and the lag went away.

7
  • 6
    +1 switching off https worked for me when --verbose told me mine was failing at npm http fetch 200 https://registry.npmjs.org/some-project/-/some-project-X.X.X.tgz Commented Sep 27, 2016 at 20:24
  • 2
    i don't know it was the https or the progress bar, but turning both off did the job! Thx! Commented Jun 9, 2017 at 8:38
  • 21
    Is it really a good idea to download code over http and then run it? The code might have been changed.
    – Mark
    Commented Jul 16, 2017 at 11:03
  • Turning off https solved everything for me. After upgrading node to the latest version, it started hanging randomly on installs. Now it works great. It's unfortunate that switching back to http solved the issue, but at least it works now. Commented Nov 10, 2017 at 21:42
  • 4
    Doesn't work currently: Beginning October 4, 2021, all connections to the npm registry - including for package installation - must use TLS 1.2 or higher
    – Matt
    Commented Aug 8, 2022 at 18:10
24

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
5
  • It now tells me that "Beginning October 4, 2021, all connections to the npm registry - including for package installation - must use TLS 1.2 or higher. You are currently using plaintext http to connect."
    – AMDP
    Commented Nov 29, 2022 at 13:56
  • When I was running npm i it was getting stuck in random dependencies. This actually works for me, do you know why this fixes the problem?
    – hfc
    Commented Dec 20, 2022 at 9:54
  • 2
    disabling ipv6 in macOS did the trick for me too, thx
    – Yevgeniy
    Commented Jan 9, 2023 at 12:54
  • This helps my case
    – syshen
    Commented Mar 27, 2023 at 12:01
  • On Linux also disable ipv6 was the solution.
    – mariofertc
    Commented Jun 10, 2023 at 22:44
22

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/
2
  • You should update it to use https instead Commented Oct 27, 2021 at 15:22
  • Don't set the registry to http instead of https - > Beginning October 4, 2021, all connections to the npm registry - including for package installation - must use TLS 1.2 or higher. You are currently using plaintext http to connect. Please visit the GitHub blog for more information: github.blog/2021-08-23-npm-registry-deprecating-tls-1-0-tls-1-1 Commented Nov 28, 2022 at 15:06
16

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.

12

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

sudo npm install -g npm@latest
2
  • See also this answer
    – crashwap
    Commented Dec 17, 2021 at 21:15
  • In my experience, npm isn't usually run with sudo (elevated user privileges). Make sure this is required for your system before running this.
    – sp3ctum
    Commented Feb 2 at 13:59
10

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

0
9

I am behind a corporate proxy, so I usually use an intermediate proxy to enable NTLM authentication.

I had hangs problem with npm install when using CNTLM proxy. With NTLM-APS (a similar proxy) the hangs were gone.

2
  • Thanks, I had the same issue and wasn't going anywhere. It's the first time CNTLM did not work for me!
    – dcendents
    Commented Dec 1, 2015 at 18:04
  • I also swithced to ntlm-aps and I saw the improvement for my npm install and meteor npm install commands.
    – Aaron C
    Commented Sep 16, 2016 at 16:26
9

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

9

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

1
  • 1
    removing the package-lock.json worked for me
    – user2988908
    Commented Mar 8, 2023 at 16:15
9

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

1
  • Worked for me too. Start simple! Commented Feb 21, 2023 at 18:23
6

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

0
4

Incase its useful to others, the following is what worked for me:

On my machine, although npm proxy was set correctly, npm install waits forever doing something like sill extract. Re-trying npm install waits forever on the same package again and again.

After waiting for a long timeout, npm install printed an error message implying that git was trying to fetch something.

The problem vanished after configuring git proxy using the below command:

git config --global http.proxy https://proxy-server:port

Note the https in the value of http.proxy without which the configuration did not take effect. Proxy server settings (http / https / port) might vary for users; hence its worth spending a bit of time experimenting with npm and git proxy server settings.

1
  • Unfortunately there's tons of problems that can cause this. Proxy settings you don't want, the npm project has too many releases or some other connectivity issue. In my case I solved one of these problems by restarting. I know it's a silly solution, but if you're pulling your hair and you didn't try this yet, I would suggest you do. I'm running Mac Os Mojave and this is not the first time I have connectivity issues where I have to restart. Something related to SSL, apparently. Commented Nov 22, 2019 at 14:54
3

The registry(https://registry.npmjs.org/cordova) was blocked by our firewall. Unblocking it fixed the issue.

2

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

1
  • 12
    seems better as a comment
    – StupidWolf
    Commented May 23, 2021 at 9:22
2

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

1
  • I tried everything above, and this is the only thing that worked for me, thank you!
    – Julian
    Commented Apr 16, 2023 at 4:59
2

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.
2
  • If you're on the VPN, disconnect. If you're not on the VPN, connect. Repeat till done. :-)
    – Rory
    Commented Jan 29, 2022 at 17:22
  • @Rory exactly my issue, but for me connecting to the VPN that had some of the resources was enough :-)
    – jave.web
    Commented Feb 22 at 20:02
2

In my case it was freezing while calling reify.

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

1
  • changing versions is not a general solution, probably worked for you by accident
    – venimus
    Commented Dec 1, 2022 at 20:39
2

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
1

This method is working for me when npm blocks 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 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 the package is working correctly with the command line.

1

I'm not sure if your problem is being caused by the same reason that mine was, but I too was experiencing a hanging "npm install" and was able to fix it.

In my case, I wanted to install typescript locally in the project:

npm i typescript --save-dev

For some reason this was conflicting with a global install of typescript that I had, and the shell was just hanging forever instead of finishing or erroring...

I fixing it by first removing the globally installed typescript with the -g global flag:

npm uninstall typescript -g

After doing this the first command worked! 👍

1

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

1

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.

1

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.

1

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

0

For anyone on MacOS (I'm on Mojave 10.14), the following helped me out: https://github.com/reactioncommerce/reaction/issues/1938#issuecomment-284207213

You'd run these commands

echo kern.maxfiles=65536 | sudo tee -a /etc/sysctl.conf
echo kern.maxfilesperproc=65536 | sudo tee -a /etc/sysctl.conf
sudo sysctl -w kern.maxfiles=65536
sudo sysctl -w kern.maxfilesperproc=65536
ulimit -n 65536

Then try npm install once more.

0

check your environment variables for http and https

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

Run "npm install" again.

0

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

0

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 ;)

Not the answer you're looking for? Browse other questions tagged or ask your own question.