npm cannot reach the registry from behind a proxy
ETIMEDOUTShort answer
npm needs to be told about your proxy. Set proxy and https-proxy (or the HTTP_PROXY and HTTPS_PROXY variables), exclude internal hosts with noproxy, and if the proxy inspects TLS, give npm its CA file with cafile. Disabling strict-ssl is not the fix.
Fix it fast
1Find out which cause you have
Print what npm currently uses for proxy and registry, and what your shell exports.
npm config get proxy npm config get https-proxy npm config get registry env | grep -i proxy2Match what you see, then jump to its fix
- 1
Timeouts or refused connections, while a browser on the same network worksNo proxy is set, so npm tries to connect directlyFix - 2
Public packages install, but a private registry or internal host failsInternal hosts are sent through the proxyFix - 3
A certificate error appears once the proxy itself is reachedThe proxy re-signs TLS and npm does not trust its certificateFix
- 1
What does the error look like?
ETIMEDOUTECONNREFUSED
Cause 1 of 3
No proxy is set, so npm tries to connect directly
1Check
Both npm proxy settings default to null. npm also honours HTTP_PROXY and HTTPS_PROXY variables, so one of those or the config must be set.
npm config get proxy
npm config get https-proxy2Fix
Set both options to your proxy URL.
npm config set proxy http://proxy.example.com:8080
npm config set https-proxy http://proxy.example.com:80803Verify
Ask the registry for a package's version.
npm view npm versionConfirmed by docs.npmjs.com
Cause 2 of 3
Internal hosts are sent through the proxy
1Check
noproxy lists domain extensions that bypass any proxy. Its default is the NO_PROXY variable.
npm config get noproxy2Fix
Add your internal domain to noproxy.
npm config set noproxy localhost,.corp.example.com3Verify
Install from the internal registry again.
npm view my-private-package versionConfirmed by docs.npmjs.com
Cause 3 of 3
The proxy re-signs TLS and npm does not trust its certificate
1Check
strict-ssl (default true) makes npm validate the registry's certificate. A company proxy that inspects traffic uses its own CA, which npm does not know.
npm config get cafile2Fix
Point cafile at the PEM file with your company's CA certificates. Keep strict-ssl on.
npm config set cafile /etc/ssl/certs/company-ca.pem3Verify
Run the install again.
npm view npm versionConfirmed by docs.npmjs.com
How do I stop it coming back?
- Keep proxy settings in the user .npmrc, not in each project, and never commit credentials in a proxy URL.
- Ask your network team for the CA bundle once and store it in a known path.
- Keep a private registry's domain in noproxy.
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