14

When I run npm install it seems to work fine until part way installing packages. It seems to have no problem with the first half, but then after a while it will fail to be able to reach other packages. I just get the repeating errors, eg:

npm http request GET https://registry.npmjs.org/react-hot-loader
npm info attempt registry request try #3 at 6:43:34 AM
npm http request GET https://registry.npmjs.org/react-tap-event-plugin
npm info attempt registry request try #3 at 6:43:34 AM
npm http request GET https://registry.npmjs.org/react-test-renderer

etc.

It will continue to do this for an hour and and then the install will fail.

The install breaks at a different package each time so I don't think it's a problem with a particular file.

I can access these files fine with my browser and curl.

My work has a firewall but this domain is whitelisted.

Would anyone know what I could do to get this to work or what could be causing it?

MeltingDog
  • 12,714
  • 38
  • 143
  • 270

7 Answers7

14

If it's about the timing problem you should find a speed solutions for npm install.

So you can try these faster command than npm install :

pnpm install %70 faster
or
npm install --no-audit 15% faster
or
npm install --prefer-offline --no-audit 15% faster

check this article for details : speeding up npm install

Guy
  • 2,653
  • 1
  • 28
  • 37
Ömür Alçin
  • 481
  • 4
  • 13
  • For me, my issue was that on a machine that doesn't have access to the internet and that installs from a private NPM registry, `npm install` would hang at the very end of the install (usually for about 4 minutes). Installing with `--no-audit` fixed my issue. Thanks! – Caleb Koch Mar 04 '22 at 14:18
12

You can override the max and min timeout in ~/.npmrc.

// npm config ls -l
// add these 2 lines in ~/.npmrc
fetch-retry-maxtimeout = 6000000
fetch-retry-mintimeout = 1000000
Stardust
  • 939
  • 3
  • 12
  • 24
Siddharth
  • 131
  • 1
  • 3
  • 7
    While this code may resolve the OP's issue, it is best to include an explanation as to how your code addresses the OP's issue. In this way, future visitors can learn from your post, and apply it to their own code. SO is not a coding service, but a resource for knowledge. Also, high quality, complete answers are more likely to be upvoted. These features, along with the requirement that all posts are self-contained, are some of the strengths of SO as a platform, that differentiates it from forums. You can edit to add additional info &/or to supplement your explanations with source documentation. – ysf Jun 08 '20 at 18:06
6

If it's still relevant or maybe for other people of interest: For me it helped, deleting the package.lock file and running npm cache clean --force.

Chris
  • 3,757
  • 3
  • 21
  • 44
  • This helped me. it turned out that npm has to small timeout values for download connections and connections where killed while downloading packages. To solve this clear cache like in this post and install dependencies one by one. – BPS Apr 06 '20 at 12:54
0

It might not be your case, but I had issues with a package being hosted at github with the repo url being only with git protocol (port 9418 not usually open on firewall).

Once added that to the firewall I could npm install without issues.

You can view the repository url with:

$ npm view zone.js repository.url
git://github.com/angular/angular.git
aseques
  • 393
  • 3
  • 17
0

I solved the timeout issue by executing these commands:

rm package-lock.json
npm i
daGo
  • 2,140
  • 21
  • 21
0

If your internet connection is the problem, try increasing the timeout:

npm config set timeout 6000000

The value is a 32-bit int.

p3s3p
  • 11
  • 3
-1
npm cache clean --force

npm install --force

It works fine.

Paul Roub
  • 35,848
  • 27
  • 79
  • 88
Gunasekar
  • 135
  • 1
  • 6
  • --force on npm install seems unrelated, here's a quote from npm help install: 'npm will refuse to install any package with an identical name to the current package. This can be overridden with the --force flag, but in most cases can simply be addressed by changing the local package name.' – Pavlo Jun 09 '20 at 15:43