Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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

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?

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
npm install --no-audit 15% faster
npm install --prefer-offline --no-audit 15% faster

check this article for details : speeding up npm install

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 4, 2022 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, 2022 at 20:15

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
                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 8, 2020 at 18:06

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

npm config set timeout 6000000

The value is a 32-bit int.

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, 2022 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 at 18:48 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 6, 2020 at 12:54

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
                @404 you just need to open the port for outgoing traffic, your firewall admin will know the specifics in your case.
– aseques
                Mar 31, 2022 at 13:45

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

    --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 9, 2020 at 15:43

    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

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.