22

npm freezes when I am installing anything. Even after deleting package-lock.json nothing changed. Here is a similar question. Can anyone tell how can I solve this problem??

enter image description here

iabhishek15
  • 343
  • 1
  • 2
  • 9

9 Answers9

13

It could be your having an issue with your certificates. Sometimes if you get this behavior there is an error in the certificate chain.

Try npm set strict-ssl false to see if this resolves your issue. Just remember if you do this you have disabled some of the security ssl gives you.

Damo
  • 5,698
  • 3
  • 37
  • 55
8

In my case being behind a VPN was causing this issue, I disconnected and it ran just fine

Mariano Argañaraz
  • 1,159
  • 11
  • 22
  • In my case it wasn't VPN but was still a network issue. My IPv6 connectivity was broken (`ping ipv6.google.com` wasn't working either). Fixing IPv6 got `npm` working again too. – Malvineous Aug 02 '23 at 07:40
3

Updating my npm using npm install -g npm@latest solved the issue.

Caio Wilson
  • 353
  • 2
  • 12
  • Can you comment on what npm you were using before and after this command? – RyanQuey Apr 27 '23 at 03:49
  • 1
    @RyanQuey sorry man, i've changed computers since then. but I think it was the default npm that comes with the nodejs package on ubuntu 22LTS and updated to the most recent at the time, probably the same as now but maybe a minor or bug version bump. – Caio Wilson May 11 '23 at 15:34
  • btw its windows related but i used to keep my windows and wsl2 node versions the same. – Caio Wilson May 11 '23 at 15:35
1

In my case, like @Damo said in their answer, it was a problem with TLS certificates (due to a corporate VPN). It was stuck at idealTree buildDeps for a long time, but eventually it finished with this error: SELF_SIGNED_CERT_IN_CHAIN.

I didn't want to run npm set strict-ssl false due to the security implications. The reason npm is getting an apparently invalid certificate is because I'm connected to the corporate VPN, which acts like a man-in-the-middle (but one that can be trusted, as opposed to most MITM situations, of course).

So the secure solution is to tell npm to trust my company's CA certificate.

This is done by npm config set cafile <path-to-cafile>.

Since I'm running an Ubuntu docker container, this is how I did it:

  1. Obtained the company's CA certificate in PEM format. 1
  2. Configured ubuntu to trust it following the steps of this answer
  3. Verified that curl https://registry.npmjs.org/ is working without certificate errors
  4. Tell npm to use the CA certificate: npm config set cafile /etc/ssl/certs/ca-certificates.crt (don't ask me why npm doesn't do this by default)

Done!


1 If you don't know who to ask for this, you can simply access any HTTPS website (such as stackoverflow) and see and download the root certificate (it won't be the standard stackoverflow certificate, because of your company's MITM VPN):

enter image description here

Pedro A
  • 3,989
  • 3
  • 32
  • 56
0

In my case it was a regresion in npm v7.x related to dependencies pointing to specific gitlab url:

"devDependencies": {
  "npm-seven-issue-dep": "git+ssh://git@gitlab.com/klesun/npm-seven-issue-dep#5f1b313978986974d4364585e6bd3689276f1697"
}

Here is the bug report.

From what I observe, this freeze takes around 60 seconds (some network timeout perhaps) then installation finishes successfully.

Klesun
  • 12,280
  • 5
  • 59
  • 52
0

I had the same issue. I figured out that my project was running in another terminal. So I closed that terminal and package was successfully installed, then I runned the project again.

0

I had this same problem, it is directly linked to your vpn, it occurs mainly if it is a competitive vpn, my suggestion is to contact your corporation support.

-1

I tried all the solutions I found on the Internet: removing the proxy, setting the ssl cert to false, removing node_modules, removing the package-lock... nothing worked...

Then, I updated my WSL Ubuntu 20.04 to 22.04 and it worked!

sudo apt update
sudo apt upgrade
sudo apt dist-upgrade
sudo apt install update-manager-core
sudo nano /etc/update-manager/release-upgrades

change the Prompt value to Prompt = lts

sudo do-release-upgrade -d
cat /etc/os-release

for more info see this link

-2

Use it:

npm install passport --legacy-peer-deps
Muslim
  • 66
  • 1
  • 8
  • 7
    See "[Explaining entirely code-based answers](https://meta.stackoverflow.com/q/392712/128421)". While this might be technically correct, it doesn't explain why it solves the problem or should be the selected answer. We should educate along with helping solve the problem. – the Tin Man Mar 22 '22 at 05:00