Error Knowledge Base NPM EAI_AGAIN

npm ERR! code EAI_AGAIN

npm could not resolve the registry hostname (DNS returned EAI_AGAIN).

Affected versions: All supported npm versions.

What This Error Means

npm could not resolve the registry hostname (DNS returned EAI_AGAIN).

How to Fix It

  1. Check which registry npm is using: npm config get registry.
  2. If the package is scoped, verify scope registry mapping in .npmrc (example: @your-scope:registry=...).
  3. Run a quick health check: npm ping.
  4. Confirm basic HTTPS connectivity from the same machine: curl -I $(npm config get registry).
  5. If you use a proxy, verify settings: npm config get proxy and npm config get https-proxy.
  6. If you do not use a proxy, remove stale proxy config: npm config delete proxy and npm config delete https-proxy.
  7. Resolve the registry host (DNS): node -e "require(\"dns\").lookup(new URL(process.argv[1]).hostname, console.log)" $(npm config get registry).
  8. If this works on a different network (hotspot) but fails on your office/VPN, fix DNS/VPN/proxy first.
  9. Retry with logs: npm --verbose (keep the full output).
  10. If this happens in CI only, compare DNS/proxy/firewall between CI and your local machine.

Why It Happens

  • DNS is unstable or blocked on your network (VPN, captive portal, split-DNS, or firewall).
  • A proxy is misconfigured (wrong proxy / https-proxy), or a corporate proxy is blocking npm traffic.
  • The registry endpoint is temporarily down or rate-limiting requests.

How to Verify

  1. Run npm ping and confirm it succeeds.
  2. Re-run the original command and confirm downloads complete without timeouts/resets.

Manual connectivity checks

  1. Resolve the registry host: node -e "require(\"dns\").lookup(new URL(process.argv[1]).hostname, console.log)" $(npm config get registry).
  2. Check TLS+HTTP from the same machine: curl -v $(npm config get registry).
  3. If behind a proxy, confirm it is used only when intended and supports HTTPS CONNECT.

Common CLI Output

npm ERR! code EAI_AGAIN

How npm talks to registries

  1. npm fetches package metadata and tarballs over HTTPS from your configured registry.
  2. Failures can happen during DNS lookup, TCP connect, TLS handshake, or while streaming the tarball.
  3. Proxy configuration (proxy / https-proxy) changes the network path and is a common root cause.

Prevention Tips

  • Use a proxy/cache registry close to your CI runners to reduce upstream variance.
  • Avoid flaky DNS by using stable resolvers in CI and on build machines.
  • Pin Node/npm versions in CI so network behavior is consistent.

Where This Can Be Triggered

github.com/npm/cli/blob/417daa72b09c5129e7390cd12743ef31bf3ddb83/lib/utils/ping.js

This is the registry request path where npm talks to the network. DNS/TLS errors like this code are raised by Node/OS during this request. - GitHub

// used by the ping and doctor commands
const npmFetch = require('npm-registry-fetch')
module.exports = async (flatOptions) => {
  const res = await npmFetch('/-/ping', { ...flatOptions, cache: false })
  return res.json().catch(() => ({}))
}

Need help or found a mistake? Contact RepoFlow support for questions.

Join our mailing list