How to fix npm ERR! code EAI_AGAIN in npm

npmINTERMEDIATEMEDIUMUpdated May 28, 2026· 1,821 views

npm fails with code EAI_AGAIN when it can't resolve registry.npmjs.org via DNS. It's usually a transient or misconfigured DNS issue you fix by testing resolution and switching DNS servers.

Quick fix

Fixes npm ERR! code EAI_AGAIN

nslookup registry.npmjs.org
# or
dig registry.npmjs.org
  1. Confirm it is really a DNS failure
  2. Retry, since EAI_AGAIN is often transient
  3. Check basic network and DNS reachability
  4. Flush the local DNS cache
npm — error
nslookup registry.npmjs.org
# or
dig registry.npmjs.org
npm ERR! code EAI_AGAIN

What this error means

EAI_AGAIN is a DNS resolution error returned by the operating system's `getaddrinfo()` call, meaning "temporary failure in name resolution." When npm connects to the registry (by default `registry.npmjs.org`), it must first resolve that hostname to an IP address. If the configured DNS resolver is unreachable, overloaded, or blocked, `getaddrinfo()` returns EAI_AGAIN and npm aborts. Unlike EAI_NONAME (the host genuinely does not exist), EAI_AGAIN signals a soft/transient failure, so a retry can succeed once connectivity or DNS is restored. In practice it most often appears behind corporate proxies/firewalls, on flaky networks, or inside containers and VMs (Docker, WSL2) where DNS is misconfigured.

Typical symptoms

  • npm install or npm publish fails with `npm ERR! code EAI_AGAIN`
  • Underlying message reads `getaddrinfo EAI_AGAIN registry.npmjs.org`
  • The hostname in the error is your registry (registry.npmjs.org, or a private/proxy registry)
  • Other network tools (git, curl, ping by name) may also fail to resolve hostnames
  • The problem is intermittent and sometimes succeeds on retry
  • Occurs more often on corporate networks, VPNs, Docker containers, or WSL2

Common causes

  1. The configured DNS server is temporarily unavailable, overloaded, or slow to respond
  2. No working network connection, or a VPN/proxy that intercepts or blocks DNS
  3. A firewall or corporate network blocking outbound DNS (port 53) or the registry host
  4. Misconfigured or stale DNS settings inside a container or VM (Docker, WSL2)
  5. A private/proxy npm registry hostname that the current network cannot resolve
  6. Stale or corrupted local DNS cache
  7. ISP DNS resolver problems

How to fix "npm ERR! code EAI_AGAIN"

1Confirm it is really a DNS failure

Try resolving the exact hostname from the error message:

bash
nslookup registry.npmjs.org
# or
dig registry.npmjs.org

If resolution fails or times out, DNS is the problem. Also check which registry npm is using, in case it is a private one that your network cannot resolve:

bash
npm config get registry
2Retry, since EAI_AGAIN is often transient

Because EAI_AGAIN means a *temporary* resolution failure, simply re-running the command after a moment frequently works:

bash
npm install

If you are behind a slow or congested DNS server, increasing npm's network timeout can also help:

bash
npm install --fetch-timeout=60000

If it succeeds intermittently, the underlying issue is a flaky resolver or network rather than a hard misconfiguration.

3Check basic network and DNS reachability

Verify you have connectivity and that DNS specifically is the failing layer:

bash
# Connectivity to a known IP (bypasses DNS)
ping -c 3 1.1.1.1

# Name resolution + HTTPS to the registry
curl -I https://registry.npmjs.org

If ping 1.1.1.1 works but curl https://registry.npmjs.org fails on name resolution, the problem is DNS. If even ping 1.1.1.1 fails, fix the network/VPN connection first.

4Flush the local DNS cache

A stale cache can keep a failed lookup around. Clear it for your OS:

bash
# macOS
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

# Windows
ipconfig /flushdns

# Linux (systemd-resolved)
sudo resolvectl flush-caches   # older systemd: sudo systemd-resolve --flush-caches
5Switch to a reliable public DNS resolver

If your ISP/corporate resolver is the culprit, point your system at a public resolver such as Cloudflare (1.1.1.1) or Google (8.8.8.8).

Important: do not hand-edit /etc/resolv.conf on most modern Linux systems — it is auto-generated and will be overwritten by NetworkManager, systemd-resolved, or your DHCP client on the next network change or reboot. Configure DNS through the manager that owns it so the change persists:

bash
# NetworkManager (find your connection name with: nmcli connection show)
sudo nmcli connection modify "<connection-name>" ipv4.dns "1.1.1.1 8.8.8.8"
sudo nmcli connection modify "<connection-name>" ipv4.ignore-auto-dns yes
sudo nmcli connection up "<connection-name>"

# systemd-resolved (global): edit /etc/systemd/resolved.conf, set
#   DNS=1.1.1.1 8.8.8.8
# then
sudo systemctl restart systemd-resolved

On macOS: System Settings > Network > your interface > Details > DNS. On Windows: change the DNS servers in the adapter's IPv4 properties (or Set-DnsClientServerAddress in PowerShell). These survive reboots, unlike a manual /etc/resolv.conf edit.

6Account for proxies and corporate firewalls

On a corporate network or VPN you may be required to use an internal DNS server and an HTTP proxy. Make sure npm is configured for the proxy:

bash
npm config set proxy http://proxy.example.com:8080
npm config set https-proxy http://proxy.example.com:8080

If you previously set a proxy that no longer applies (e.g. after leaving the VPN), clear it:

bash
npm config delete proxy
npm config delete https-proxy

Confirm with your network admin that outbound DNS (UDP/TCP 53, or DoH/DoT) and access to the registry host are permitted.

7Fix DNS inside containers and VMs

If the error only happens inside Docker or WSL2, the container/VM DNS config is usually the cause.

bash
# Docker: run with explicit resolvers
docker run --dns 1.1.1.1 --dns 8.8.8.8 ...

Or set DNS persistently in Docker's /etc/docker/daemon.json:

json
{
  "dns": ["1.1.1.1", "8.8.8.8"]
}

then sudo systemctl restart docker. For Kubernetes, check CoreDNS/kube-dns pod health (kubectl get pods -n kube-system). For WSL2, see the Advanced notes below.

Advanced notes

WSL2 generates /etc/resolv.conf automatically and will overwrite manual edits unless you disable that behavior. To pin custom DNS, add to /etc/wsl.conf:

ini
[network]
generateResolvConf = false

then wsl --shutdown from Windows, reopen WSL, and write your own /etc/resolv.conf with nameserver 1.1.1.1.

If you must use a temporary hosts-file workaround, never hardcode a guessed IP — registry.npmjs.org is served by Cloudflare with rotating, geo-distributed addresses, so a stale entry causes more outages than it fixes. Resolve the current IP yourself (dig +short registry.npmjs.org) only if absolutely necessary, and remove the entry as soon as DNS works again; the durable fix is correcting the resolver, not pinning an IP.

EAI_AGAIN can also surface when the registry is reachable but rate-limited or returning errors slowly; if DNS clearly resolves (dig succeeds) yet npm still reports EAI_AGAIN, suspect a proxy/firewall doing DNS interception rather than your resolver itself.

Frequently asked questions

What does "npm ERR! code EAI_AGAIN" mean?
org), it must first resolve that hostname to an IP address. If the configured DNS resolver is unreachable, overloaded, or blocked, getaddrinfo() returns EAI_AGAIN and npm aborts. Unlike EAI_NONAME (the host genuinely does not exist), EAI_AGAIN signals a soft/transient failure, so a retry can succeed once connectivity or DNS is restored.
How do I fix "npm ERR! code EAI_AGAIN"?
npm fails with code EAI_AGAIN when it can't resolve registry.npmjs.org via DNS. It's usually a transient or misconfigured DNS issue you fix by testing resolution and switching DNS servers.
What causes "npm ERR! code EAI_AGAIN"?
The configured DNS server is temporarily unavailable, overloaded, or slow to respond No working network connection, or a VPN/proxy that intercepts or blocks DNS A firewall or corporate network blocking outbound DNS (port 53) or the registry host
Is the "npm ERR! code EAI_AGAIN" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading