How to Fix NPM Timeout Errors on Slow Internet Connections

In Nodejs on 2~3 minutes
How to Fix NPM Timeout Errors on Slow Internet Connections

Sometimes when we work with slow or unstable Internet connections, npm often fails to complete its commands like npm install and npm update with a timeout error. For that kind of situation, we can simply change some npm configurations like fetch-retries, fetch-retry-mintimeout, fetch-retry-maxtimeout and cache-min to minimize these timeout errors.

fetch-retries

This config controls the number of times npm try to connect to the registry when fetching packages. The default value is 2, but you can increase it to 3~5 or even more if you like. Open a terminal window and run the following command with the desired number of retries at the end.

npm config set fetch-retries 3

fetch-retry-mintimeout

This config controls the minimum time (in milliseconds) npm wait before timing out when fetching packages from the registry. The default value is 10000 milliseconds (10 seconds), change it to 100000 or more.

npm config set fetch-retry-mintimeout 100000

fetch-retry-maxtimeout

This config controls the maximum time (in milliseconds) npm wait before timing out when fetching packages from the registry. The default value is 10000 milliseconds (10 seconds), change it to 600000 or more.

npm config set fetch-retry-maxtimeout 600000

cache-min

This config controls the minimum time (in seconds) to keep items before re-checking the registry. The default value is 10 seconds, change it to 3600 seconds (1 hour) or more.

npm config set cache-min 3600

Finally, run this command to check whether all the configuration changes are successfully applied or not.

npm config ls -l

Now try to run some failing commands to check whether they are working. The duration values mentioned in this question was only for demonstration, you may try different values by increasing and decreasing them according to your situation. Visit npm-config documentation for more available configurations.

Share: