How to fix npm ERR! code EHOSTUNREACH in npm
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.
Quick fix
Fixes npm ERR! code EHOSTUNREACH
curl -v https://registry.npmjs.org
ping registry.npmjs.org- Test connectivity to npm registry
- Trace the route to registry
- Check local firewall rules
- Try using a proxy
curl -v https://registry.npmjs.orgping registry.npmjs.orgnpm ERR! code EHOSTUNREACH
What this error means
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.
Typical symptoms
- npm install fails with connect EHOSTUNREACH
- Other websites work but npm registry does not
- Error appears after brief connection attempt
- Problem may be intermittent
- Direct IP access to registry also fails
- Traceroute stops at a certain hop
Common causes
- Firewall blocking registry.npmjs.org
- Corporate proxy not allowing npm traffic
- ISP blocking or routing issues
- npm registry IP range blocked
- Regional network issues
- Host-based firewall rules
- VPN routing configuration
How to fix "npm ERR! code EHOSTUNREACH"
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
Advanced notes
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.
Frequently asked questions
- What does "npm ERR! code EHOSTUNREACH" mean?
- 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.
- How do I fix "npm ERR! code EHOSTUNREACH"?
- 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.
- What causes "npm ERR! code EHOSTUNREACH"?
- Firewall blocking registry.npmjs.org Corporate proxy not allowing npm traffic ISP blocking or routing issues
- Is the "npm ERR! code EHOSTUNREACH" error serious?
- It is a medium-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐npm Official Documentation
- ๐
- ๐ฌStack Overflow: npm+network(Stack Overflow)