How to fix npm ERR! code ENETUNREACH in npm

npmINTERMEDIATEHIGHUpdated Dec 6, 2025ยท 189 views

The ENETUNREACH error means npm cannot reach the network to connect to the registry. This indicates a network routing problem, disconnected network, or firewall blocking outbound connections.

Quick fix

Fixes npm ERR! code ENETUNREACH

# Linux
ip addr
ip link show

# macOS
ifconfig

# Windows
ipconfig /all
  1. Check network interface status
  2. Test basic connectivity
  3. Check routing table
  4. Force IPv4 for npm
npm โ€” error
# Linux
ip addr
ip link show
# macOS
ifconfig
# Windows
ipconfig /all
npm ERR! code ENETUNREACH

What this error means

ENETUNREACH stands for "Network Unreachable" and is a low-level network error. It occurs when your system has no route to the destination network where the npm registry resides. This is different from connection refused (server rejects) or timeout (server doesn't respond) - with ENETUNREACH, the packets cannot even leave your network. This typically indicates a fundamental network configuration problem rather than an npm-specific issue.

Typical symptoms

  • npm install fails immediately with network unreachable
  • Error includes connect ENETUNREACH message
  • Other internet services may also be unreachable
  • Problem persists across npm retries
  • ping to external addresses fails
  • Issue appears suddenly without config changes

Common causes

  1. No active network connection
  2. Network interface is down
  3. Default gateway not configured
  4. Routing table misconfiguration
  5. VPN disconnected but routing still points to it
  6. Firewall blocking all outbound traffic
  7. IPv6 address used but IPv6 not available

How to fix "npm ERR! code ENETUNREACH"

1Check network interface status

Verify your network interfaces are up:

bash
# Linux
ip addr
ip link show

# macOS
ifconfig

# Windows
ipconfig /all

Look for your active interface (eth0, wlan0, en0).

2Test basic connectivity

Check if you can reach external networks:

bash
ping -c 4 8.8.8.8
ping -c 4 google.com

If ping fails, the issue is network-level, not npm.

3Check routing table

Verify you have a default route:

bash
# Linux/macOS
ip route  # or route -n
netstat -rn

# Windows
route print

You should see a default route (0.0.0.0/0) pointing to your gateway.

4Force IPv4 for npm

Sometimes IPv6 routing fails while IPv4 works:

bash
npm config set prefer-ipv4 true
# or use Node.js flag
NODE_OPTIONS="--dns-result-order=ipv4first" npm install
5Restart network services

Restart networking to reset connections:

bash
# Linux
sudo systemctl restart NetworkManager
# or
sudo service networking restart

# macOS - toggle Wi-Fi or:
sudo ifconfig en0 down && sudo ifconfig en0 up
6Check VPN and firewall

If using VPN, ensure it's connected or fully disconnected:

bash
# Check for VPN interfaces
ip addr | grep -E "tun|tap|wg"

# Temporarily disable firewall to test
sudo ufw disable  # Linux

Re-enable firewall after testing.

Advanced notes

In Docker, ENETUNREACH often indicates the container network is misconfigured. Try --network=host for testing. In Kubernetes, check pod network policies and CNI plugin status. For WSL2, network issues can occur when Windows networking changes - try wsl --shutdown and restart. Some corporate VPNs use split tunneling that may not include npm registry routes.

Frequently asked questions

What does "npm ERR! code ENETUNREACH" mean?
ENETUNREACH stands for "Network Unreachable" and is a low-level network error. It occurs when your system has no route to the destination network where the npm registry resides. This is different from connection refused (server rejects) or timeout (server doesn't respond) - with ENETUNREACH, the packets cannot even leave your network.
How do I fix "npm ERR! code ENETUNREACH"?
The ENETUNREACH error means npm cannot reach the network to connect to the registry. This indicates a network routing problem, disconnected network, or firewall blocking outbound connections.
What causes "npm ERR! code ENETUNREACH"?
No active network connection Network interface is down Default gateway not configured
Is the "npm ERR! code ENETUNREACH" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading