Skip to content
Latchkey

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 output
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.org

Common 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.

Terminal
# 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

  1. Cache ~/.npm so most packages resolve from disk, not the network.
  2. Point at an internal mirror reachable from the build network.
  3. 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.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →