npm install stops with ERR_SOCKET_TIMEOUT on a slow or filtered network
npm ERR! code ERR_SOCKET_TIMEOUTShort 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.
Fix it fast
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"2Match what you see, then jump to its fix
- 1
The error appears after a long pause, on large installs or on weak Wi-FiThe link is slow and npm gives up too soonFix - 2
Other tools work through a company proxy, but npm times out; proxy shows nullThe network needs a proxy that npm does not know aboutFix - 3
The 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
- 1
What does the error look like?
npm ERR! code ERR_SOCKET_TIMEOUTnpm 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 6000003Verify
Run the install again.
npm installConfirmed by docs.npmjs.com
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:80803Verify
The install now gets past the registry request.
npm installConfirmed by docs.npmjs.com
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 registry2Fix
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 installConfirmed by docs.npmjs.com
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 fixBack end
ng fails with Cannot find module @angular/cli/bin/ng
Cannot find module '@angular/cli/bin/ng'
The ng command is the entry point to the Angular CLI package.
2 causes, each with a fixBack end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fixBack 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 fixBack end
Angular build says it cannot resolve '@angular/localize/init'
Can't resolve '@angular/localize/init' in '/usr/src/app/src'
The build imports @angular/localize, and that package is not in node_modules.
2 causes, each with a fixBack end
The command npm run build -- --prod exited with code 1 (Angular)
The command "npm run build -- --prod" exited with code 1
Exit code 1 only says the build failed; the real message is above it.
2 causes, each with a fix