31

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
  • 14,310
  • 43
  • 165
  • 295

10 Answers10

26

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,883
  • 1
  • 32
  • 39
Ömür Alçin
  • 619
  • 7
  • 15
  • 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
  • pnpm caches the node_modules in your local file system so it makes sense that it's faster than npm locally, but is pnpm always faster in a fresh environment like Docker? – Yao Oct 27 '22 at 20:15
20

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
  • 999
  • 3
  • 12
  • 24
Siddharth
  • 311
  • 2
  • 3
  • 10
    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
12

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

npm config set timeout 6000000

The value is a 32-bit int.

p3s3p
  • 131
  • 1
  • 5
  • 1
    This was exactly my problem on a WLAN, thank you! I assume it's milliseconds, so that `6000000 / 1000 / 60` = timeout of 100 minutes? – kungfooman Nov 14 '22 at 15:56
  • @kungfooman it's 10 minutes. (600000 miliseconds/1000 miliseconds per second) -> 600 seconds / 60 seconds per minute --> 10 minutes – Mike Graf Apr 19 '23 at 18:48
  • 2
    I've started getting the error `The "timeout" argument must be of type number. Received type string` after running this command. – Eliezer Berlin Jun 14 '23 at 08:39
7

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
  • 4,238
  • 4
  • 28
  • 49
  • 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
1

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
  • 537
  • 4
  • 21
1

I saw an answer earlier that can resolve your problem by overriding the max and min timeout in ~/.npmrc file, but some didn't understand how to do it. First go to the nodejs folder - for me it's located at ( Y:\Program Files\nodejs )

  • Open the node_modules folder.
  • Then npm folder.
  • Select (.npmrc) file + right click and open it with any text editor you want.
  • Finally add these 2 lines and click Ctrl+S
fetch-retry-maxtimeout = 6000000
fetch-retry-mintimeout = 1000000

.npmrc file after modification

0
npm cache clean --force

npm install --force

It works fine.

Paul Roub
  • 36,322
  • 27
  • 84
  • 93
Gunasekar
  • 145
  • 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
0

If you are on windows, try running vscode as administrator, it worked for me, I tried npm config delete https-proxy , npm config delete proxy and , tried deleting node_modules, and package.lock.json and ran npm cache clean --force but at last ran vscode as adminitrator before deleting node_modules and package.lock.json, it worked

ashrth
  • 63
  • 7
0

You can extend timeout with those two commands:

npm config set fetch-retry-maxtimeout 6000000
npm config set fetch-retry-mintimeout 1000000

enter image description here

Source: https://docs.npmjs.com/cli/v9/using-npm/config#fetch-retry-maxtimeout

smartmouse
  • 13,912
  • 34
  • 100
  • 166
-2

I solved the timeout issue by executing these commands:

rm package-lock.json
npm i
daGo
  • 2,584
  • 26
  • 24