npm install fails with getaddrinfo ENOTFOUND registry.npmjs.org
npm error code ENOTFOUNDShort answer
ENOTFOUND means a DNS lookup for the host failed, so npm never connected. Print npm's registry and proxy settings first: a stale mirror, a dead proxy variable or a bad .npmrc line is the usual cause. If those are clean, test DNS from the same shell, especially inside a container.
Fix it fast
1Find out which cause you have
See which registry and proxies npm will actually use.
npm config get registry npm config get proxy npm config get https-proxy2Match what you see, then jump to its fix
- 1
npm config get proxy or https-proxy prints a value you did not expectA proxy setting or proxy environment variable points at a host that does not resolveFix - 2
npm config get registry does not print https://registry.npmjs.org/The registry setting is a wrong or retired hostFix - 3
npm works on the host but fails only in a container build or runThe container or its network has no working DNSFix
- 1
What does the error look like?
npm error code ENOTFOUNDnpm error errno ENOTFOUNDnpm error network request to https://registry.npmjs.org/express failed, reason: getaddrinfo ENOTFOUND registry.npmjs.org
Cause 1 of 3
A proxy setting or proxy environment variable points at a host that does not resolve
1Check
npm honours HTTP_PROXY, HTTPS_PROXY and their lowercase forms, as well as its own proxy and https-proxy settings. An old value left from another network makes every request fail.
env | grep -i proxy
npm config get proxy2Fix
Remove the stale setting, or set the right one. Use noproxy for hosts that must bypass the proxy.
npm config delete proxy
npm config delete https-proxy
unset HTTP_PROXY HTTPS_PROXY http_proxy https_proxy3Verify
Run the install again.
npm installConfirmed by docs.npmjs.com
Cause 2 of 3
The registry setting is a wrong or retired host
1Check
The default registry is https://registry.npmjs.org/. A line in .npmrc may override it with a host that no longer exists.
npm config get registry
grep -n registry .npmrc ~/.npmrc 2>/dev/null2Fix
Delete the override or set the default back.
npm config set registry=https://registry.npmjs.org/3Verify
Run the install again.
npm installConfirmed by docs.npmjs.com
Cause 3 of 3
The container or its network has no working DNS
1Check
Containers on the default bridge copy the host's DNS servers; user-defined networks use Docker's embedded DNS at 127.0.0.11. Node.js reports ENOTFOUND when the DNS lookup fails. Look up the name from inside the container.
docker run --rm node:22 getent hosts registry.npmjs.org
docker run --rm node:22 cat /etc/resolv.conf2Fix
Fix DNS on the Docker host first. If you must, name the DNS servers for that container with --dns.
docker run --rm --dns 1.1.1.1 node:22 getent hosts registry.npmjs.org3Verify
The name resolves inside the container.
docker run --rm --dns 1.1.1.1 node:22 getent hosts registry.npmjs.orgConfirmed by docs.docker.com
How do I stop it coming back?
- Keep proxy settings in one place per machine and remove them when you leave the network that needed them.
- Commit a project .npmrc only for settings the whole team needs, and document any custom registry.
- Print npm config get registry as the first step in a CI job that has network problems.
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
Related fixes
Back end
Node.js https request fails with getaddrinfo ENOTFOUND
getaddrinfo ENOTFOUND
ENOTFOUND means the name lookup failed before any connection was made.
3 causes, each with a fixBack end
npm cannot reach the registry from behind a proxy
ECONNREFUSED
npm needs to be told about your proxy.
3 causes, each with a fixBack end
Kong Gateway returns 502 'An invalid response was received from the upstream server'
upstream sent too big header while reading response header from upstream
Kong returns 502 when it cannot get a valid HTTP response from the upstream.
4 causes, each with a fixBack end
Puppeteer leaves Chrome running after your Express route finishes
Chrome processes still listed by ps after the request has finished
Chrome stays alive when browser.close() is never reached.
3 causes, each with a fixBack end
Puppeteer times out after 30000 ms on goto, setContent or pdf
page.goto, page.setContent or page.pdf rejects after exactly 30 seconds
Thirty seconds is Puppeteer's default timeout for navigation and for page.pdf.
4 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 fix