The EHOSTUNREACH error occurs when npm can reach the network but the specific host (registry.npmjs.org) is unreachable. This typically indicates routing issues, firewall blocks, or the host being temporarily down.
EHOSTUNREACH means "Host Unreachable" - your system can communicate on the network but cannot establish a route to the specific destination host. Unlike ENETUNREACH (entire network unreachable), EHOSTUNREACH suggests the network is working but the path to the npm registry specifically is blocked or unavailable. This often occurs when firewalls block specific destinations, when there are routing issues to certain IP ranges, or when the destination host is experiencing problems.
Check if you can reach the registry directly:
curl -v https://registry.npmjs.org
ping registry.npmjs.orgNote which step fails.
Find where packets are being dropped:
traceroute registry.npmjs.org
# Windows
tracert registry.npmjs.orgLook for where the trace stops or times out.
Verify your firewall allows HTTPS outbound:
# Linux (ufw)
sudo ufw status
# Linux (iptables)
sudo iptables -L -n
# macOS
sudo pfctl -srEnsure port 443 outbound is allowed.
Route through a proxy that can reach npm:
npm config set proxy http://proxy.example.com:8080
npm config set https-proxy http://proxy.example.com:8080Try a different npm registry mirror:
npm config set registry https://registry.npmmirror.com
# or
npm install --registry https://registry.npmmirror.comIf on corporate network:
1. Contact IT about npm registry access
2. Request registry.npmjs.org be whitelisted
3. Ask about approved npm proxy/mirror
4. Check if VPN is required for external access
Some organizations use SSL inspection that can cause certificate issues with npm. If your company has an internal npm registry (Artifactory, Nexus, Verdaccio), configure npm to use it. In cloud environments (AWS, GCP, Azure), check security groups and network ACLs. For Kubernetes, verify egress network policies allow traffic to npm registry IPs.
npm ERR! code ENOAUDIT npm ERR! Audit endpoint not supported
How to fix "npm ERR! code ENOAUDIT - Audit endpoint not supported"
npm ERR! code EBADDEVENGINES npm ERR! devEngines.runtime incompatible with current node version
How to fix "npm ERR! code EBADDEVENGINES - devEngines.runtime incompatible with current node version"
npm ERR! code ETOOMANYARGS npm ERR! Too many arguments
How to fix "npm ERR! code ETOOMANYARGS - Too many arguments"
npm ERR! code EINVALIDTAGNAME npm ERR! Invalid tag name: tag names cannot contain spaces
How to fix "npm ERR! code EINVALIDTAGNAME - tag names cannot contain spaces"
npm ERR! code E400 npm ERR! 400 Bad Request
How to fix "npm ERR! code E400 - 400 Bad Request" error