How to fix npm ERR! code EHOSTUNREACH in npm

npmINTERMEDIATEMEDIUMUpdated Dec 6, 2025ยท 193 views

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
  1. Test connectivity to npm registry
  2. Trace the route to registry
  3. Check local firewall rules
  4. Try using a proxy
npm โ€” error
curl -v https://registry.npmjs.org
ping registry.npmjs.org
npm 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

  1. Firewall blocking registry.npmjs.org
  2. Corporate proxy not allowing npm traffic
  3. ISP blocking or routing issues
  4. npm registry IP range blocked
  5. Regional network issues
  6. Host-based firewall rules
  7. VPN routing configuration

How to fix "npm ERR! code EHOSTUNREACH"

1Test connectivity to npm registry

Check if you can reach the registry directly:

bash
curl -v https://registry.npmjs.org
ping registry.npmjs.org

Note which step fails.

2Trace the route to registry

Find where packets are being dropped:

bash
traceroute registry.npmjs.org
# Windows
tracert registry.npmjs.org

Look for where the trace stops or times out.

3Check local firewall rules

Verify your firewall allows HTTPS outbound:

bash
# Linux (ufw)
sudo ufw status

# Linux (iptables)
sudo iptables -L -n

# macOS
sudo pfctl -sr

Ensure port 443 outbound is allowed.

4Try using a proxy

Route through a proxy that can reach npm:

bash
npm config set proxy http://proxy.example.com:8080
npm config set https-proxy http://proxy.example.com:8080
5Use alternative registry

Try a different npm registry mirror:

bash
npm config set registry https://registry.npmmirror.com
# or
npm install --registry https://registry.npmmirror.com
6Check corporate network policies

If 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