npm EAI_AGAIN "getaddrinfo EAI_AGAIN" - Fix Temporary DNS Failure in CI
EAI_AGAIN is a temporary DNS resolution failure - the resolver could not answer in time. It is the "try again" sibling of ENOTFOUND, and inside Docker builds it usually means the build had no working DNS.
What this error means
npm fails with getaddrinfo EAI_AGAIN for the registry host, very often during a docker build step. The same install works on the host but fails in the build container, pointing at DNS inside the build environment.
npm error code EAI_AGAIN
npm error syscall getaddrinfo
npm error errno EAI_AGAIN
npm error request to https://registry.npmjs.org/... failed,
reason: getaddrinfo EAI_AGAIN registry.npmjs.orgCommon causes
No working DNS resolver in the build container
A docker build (especially with a custom network or behind a proxy) may have no usable resolver, so name lookups fail temporarily with EAI_AGAIN.
A transient resolver overload
A momentarily overloaded DNS server returns EAI_AGAIN rather than a hard failure; retrying typically succeeds.
How to fix it
Give the build a working resolver
Configure DNS for the Docker build, or retry past the transient failure.
# transient: just retry the job, or raise npm retries
npm config set fetch-retries 5
# docker build with an explicit resolver
docker build --network=host -t app .
# or set DNS in the daemon: { "dns": ["1.1.1.1","8.8.8.8"] }Reduce DNS reliance
- Cache
~/.npmso most packages resolve from disk, not the network. - Point at an internal mirror reachable from the build network.
- Confirm the proxy/firewall permits DNS from inside the build.
How to prevent it
- Ensure Docker builds have a working DNS resolver.
- Raise fetch-retries so temporary lookups recover.
- Cache the npm cache to cut DNS lookups.