Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

npm install stops with ERR_SOCKET_TIMEOUT on a slow or filtered network

Errornpm ERR! code ERR_SOCKET_TIMEOUT

Short answer

ERR_SOCKET_TIMEOUT means npm waited for the registry and the connection stalled. Check which registry npm uses, set proxy and https-proxy if you are behind one, and raise fetch-timeout and the fetch-retry settings for a slow link. Then run npm install again.

  • Applies to npm 10, npm 11, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Print the settings that decide where npm connects and how long it waits.

    npm config ls -l | grep -E "registry|fetch-|proxy"
  2. 2Match what you see, then jump to its fix

    1. 1The error appears after a long pause, on large installs or on weak Wi-FiThe link is slow and npm gives up too soonFix
    2. 2Other tools work through a company proxy, but npm times out; proxy shows nullThe network needs a proxy that npm does not know aboutFix
    3. 3The registry address printed in the first step is not https://registry.npmjs.org/ and that host is slow or unreachableA project or user .npmrc points at a different registryFix

What does the error look like?

  • npm ERR! code ERR_SOCKET_TIMEOUT
  • npm ERR! network Socket timeout

Cause 1 of 3

The link is slow and npm gives up too soon

1Check

The defaults are 2 retries, a 10 second minimum and 60 second maximum retry wait, and a 5 minute fetch timeout.

npm config ls -l | grep fetch-

2Fix

Allow more retries and longer waits for this project.

npm config set fetch-retries 5
npm config set fetch-retry-mintimeout 20000
npm config set fetch-retry-maxtimeout 120000
npm config set fetch-timeout 600000

3Verify

Run the install again.

npm install

Confirmed by docs.npmjs.com

Did this fix it?

Cause 2 of 3

The network needs a proxy that npm does not know about

1Check

npm uses proxy and https-proxy, and also honours the HTTP_PROXY and HTTPS_PROXY environment variables. Both settings default to null.

npm config ls -l | grep proxy
echo "$HTTPS_PROXY"

2Fix

Set the proxy URL your network gives you.

npm config set proxy http://proxy.example.com:8080
npm config set https-proxy http://proxy.example.com:8080

3Verify

The install now gets past the registry request.

npm install

Confirmed by docs.npmjs.com

Did this fix it?

Cause 3 of 3

A project or user .npmrc points at a different registry

1Check

npm reads the project .npmrc first, then the user file, then the global file. Find which one sets registry.

npm config ls -l | grep registry

2Fix

Remove the wrong value, or set the registry you intend.

npm config set registry https://registry.npmjs.org/

3Verify

Confirm the registry and run the install.

npm config ls -l | grep registry; npm install

Confirmed by docs.npmjs.com

Did this fix it?

How do I stop it coming back?

  • Put registry and proxy settings in the project .npmrc so every machine and CI runner uses the same values.
  • Cache dependencies in CI so a slow registry hit is rare.
  • Compare the output of npm config ls -l between a machine that works and one that fails.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

ng serve says it cannot determine the project or target

Cannot determine project for command.

The Angular CLI looked through angular.json for a project that defines the target you asked for (serve, build, test) and found none, or found several and could not pick one.

3 causes, each with a fix

Back end

ng serve cannot find the dev-server builder package

Could not find the implementation for builder @angular/build:dev-server

The builder named in angular.json (for example @angular-devkit/build-angular:dev-server) is looked up as an npm package starting from the workspace root.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.