EAI_FAIL is a DNS resolution error indicating npm cannot resolve the registry hostname. Check your internet connection, configure DNS servers, or verify proxy settings.
The EAI_FAIL error indicates a temporary failure in DNS name resolution. When npm tries to install packages, it needs to resolve the hostname of the npm registry (registry.npmjs.org) to an IP address via DNS lookup. If the DNS server cannot resolve the hostname, or the DNS request times out, Node.js returns this error. This is typically a network connectivity issue rather than a problem with npm itself, and the error may be transient—meaning it could succeed on a retry.
Verify that your network is working and can reach the npm registry:
ping registry.npmjs.orgIf ping fails, your network cannot reach external hosts. Check your internet connection, restart your router, and ensure no firewall is blocking outbound traffic.
Sometimes npm cache becomes corrupted or stale. Clear it and retry:
npm cache clean --force
npm installIf the error is transient, the retry should succeed.
Check if you have proxy settings configured that are causing the issue:
npm config listLook for 'proxy' and 'https-proxy' entries. If they are set and causing problems, remove them:
npm config rm proxy
npm config rm https-proxyIf you're behind a corporate proxy, configure npm correctly:
npm config set proxy http://[username:password@]proxy.company.com:[port]
npm config set https-proxy http://[username:password@]proxy.company.com:[port]If your network's DNS server is misconfigured, switching to a public DNS resolver often fixes the issue.
For Linux/WSL, edit /etc/resolv.conf:
sudo nano /etc/resolv.confAdd one of these nameservers at the top:
nameserver 1.1.1.1 # Cloudflare
nameserver 8.8.8.8 # Google
nameserver 9.9.9.9 # Quad9Save and exit. Then retry npm install.
Network adapters can become stale or misconfigured. A restart often resolves transient DNS issues:
# Linux/WSL: restart networking
sudo systemctl restart networking
# Windows: reset network adapter
ipconfig /release
ipconfig /renewThen try npm install again.
If all else fails, try connecting to a different network (mobile hotspot, public WiFi) and retry:
npm installIf npm works on a different network, the issue is with your current network configuration. Contact your network administrator to verify DNS is working and registry.npmjs.org is accessible.
The EAI_FAIL error is fundamentally a DNS resolution failure. Node.js does not perform DNS caching—it delegates all DNS resolution to the operating system, which means the issue is almost always environmental. In Docker, the container's DNS configuration is inherited from the host at startup; if the host's network changes after the container starts, the container may retain stale DNS info. WSL2 users commonly see this error when corporate networks intercept DNS traffic—using public resolvers like Cloudflare (1.1.1.1) or Google (8.8.8.8) bypasses these restrictions.
npm ERR! code E401 npm ERR! 401 Unauthorized - Token has expired
Token has expired - npm authentication failure
npm ERR! code EAI_NODATA npm ERR! errno EAI_NODATA npm ERR! getaddrinfo EAI_NODATA registry.npmjs.org
How to fix "npm ERR! code EAI_NODATA - getaddrinfo EAI_NODATA"
npm ERR! code EMPTYPACKAGE npm ERR! Package contains no files
How to fix 'npm ERR! code EMPTYPACKAGE' - Package contains no files
npm ERR! code EWORKSPACEMISSING npm ERR! Workspace does not exist: packages/missing
How to fix "npm ERR! code EWORKSPACEMISSING - Workspace does not exist" error
npm ERR! code EADDRNOTAVAIL npm ERR! errno EADDRNOTAVAIL npm ERR! Address not available
How to fix "npm ERR! code EADDRNOTAVAIL - Address not available" error