This error occurs when npm cannot resolve the DNS address for the npm registry. Common causes include network connectivity issues, misconfigured DNS servers, incorrect proxy settings, or VPN/firewall interference blocking the connection.
The ENOTFOUND error in npm indicates a DNS resolution failure - your system cannot translate the registry hostname (registry.npmjs.org) into an IP address. This is a network-level issue that prevents npm from even reaching the registry server. When you run `npm install`, npm first needs to resolve the domain name of the registry to its IP address using DNS. If this lookup fails, you'll see the ENOTFOUND error. The actual error originates from Node.js's `getaddrinfo` function, which performs the DNS lookup. This error is distinct from authentication errors (E401) or package-not-found errors (E404) - with ENOTFOUND, npm never successfully contacts the registry at all. The problem lies between your machine and the DNS resolution process.
First, confirm you have basic internet access:
# Try pinging a reliable host
ping 8.8.8.8
# Try resolving the npm registry
nslookup registry.npmjs.org
# Or on systems without nslookup
host registry.npmjs.orgIf ping to 8.8.8.8 works but nslookup fails, you have a DNS problem. If both fail, you have a general connectivity issue.
You can also try opening https://registry.npmjs.org in a browser - if it loads, the issue is specific to how npm resolves DNS.
Incorrect proxy settings are a common cause. Check your current npm proxy configuration:
npm config get proxy
npm config get https-proxyIf these return values and you're not behind a proxy, remove them:
npm config delete proxy
npm config delete https-proxyAlso check for environment variables that might set proxy:
# On macOS/Linux
echo $HTTP_PROXY
echo $HTTPS_PROXY
echo $NO_PROXY
# On Windows
echo %HTTP_PROXY%
echo %HTTPS_PROXY%If these are set incorrectly, unset them:
# On macOS/Linux
unset HTTP_PROXY
unset HTTPS_PROXY
# On Windows PowerShell
$env:HTTP_PROXY = ""
$env:HTTPS_PROXY = ""Sometimes the registry URL gets corrupted or set incorrectly. Reset it explicitly:
npm config set registry https://registry.npmjs.org/Verify the setting:
npm config get registryThis should return exactly https://registry.npmjs.org/.
If your DNS server is the problem, switch to a public DNS like Google (8.8.8.8) or Cloudflare (1.1.1.1):
On macOS:
1. Open System Preferences > Network
2. Select your network connection and click "Advanced"
3. Go to the DNS tab
4. Add 8.8.8.8 and 8.8.4.4 (or 1.1.1.1 and 1.0.0.1)
On Linux (Ubuntu/Debian):
# Edit resolv.conf
sudo nano /etc/resolv.conf
# Add or replace nameserver lines:
nameserver 8.8.8.8
nameserver 8.8.4.4Note: On systems using NetworkManager or systemd-resolved, changes to resolv.conf may be overwritten. Use your distribution's network settings GUI or configure the DNS server in your network manager.
On Windows:
1. Open Control Panel > Network and Internet > Network Connections
2. Right-click your connection and select Properties
3. Select "Internet Protocol Version 4" and click Properties
4. Choose "Use the following DNS server addresses"
5. Enter 8.8.8.8 and 8.8.4.4
After changing DNS, flush the DNS cache:
# macOS
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
# Linux
sudo systemd-resolve --flush-caches
# Windows
ipconfig /flushdnsClearing the npm cache can resolve some network-related issues:
npm cache clean --forceThen retry your npm command.
Review your .npmrc file for any problematic settings:
# On macOS/Linux
cat ~/.npmrc
# On Windows
type %USERPROFILE%\.npmrcLook for any registry, proxy, or other network-related settings that might be wrong. If in doubt, you can temporarily rename the file to test without it:
mv ~/.npmrc ~/.npmrc.backup
npm installIf npm works without .npmrc, review the file's contents and remove problematic lines.
VPNs and security software (antivirus, firewalls) can interfere with DNS resolution:
1. Temporarily disconnect from your VPN
2. Disable any firewall or security software
3. Try running npm install again
If npm works after disabling these, you'll need to configure exceptions:
- VPN: Configure split tunneling to exclude npm registry traffic, or use the VPN's DNS servers
- Firewall: Allow outbound connections to registry.npmjs.org on ports 443 (HTTPS) and 80 (HTTP)
- Corporate proxy: Get the correct proxy settings from your IT department
### Docker and Container Environments
Docker containers may not have DNS configured correctly by default:
# In Dockerfile, explicitly set DNS
RUN echo "nameserver 8.8.8.8" > /etc/resolv.confOr when running the container:
docker run --dns 8.8.8.8 your-imageFor Docker Compose:
services:
app:
dns:
- 8.8.8.8
- 8.8.4.4### CI/CD Pipeline Configuration
In CI/CD environments, you may need explicit registry configuration:
GitHub Actions:
- name: Setup npm registry
run: |
npm config set registry https://registry.npmjs.org/
npm config set strict-ssl trueGitLab CI:
before_script:
- npm config set registry https://registry.npmjs.org/### Corporate Network / Proxy Configuration
If you're behind a corporate proxy, configure npm to use it:
npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080
# If the proxy requires authentication
npm config set proxy http://username:[email protected]:8080For NTLM proxies, you may need a local proxy tool like Cntlm.
### IPv6 Issues
Some networks have broken IPv6 that can cause DNS issues. Try disabling IPv6 for npm:
npm config set prefer-offline false
npm config set prefer-online trueOr system-wide on Linux:
# Temporarily disable IPv6
sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1### Using a Mirror Registry
If the main npm registry is unreachable from your location, try a mirror:
# Taobao mirror (popular in China)
npm config set registry https://registry.npmmirror.com
# Or use yarn with a different registry
yarn config set registry https://registry.npmmirror.comRemember to switch back to the official registry when the issue is resolved:
npm config set registry https://registry.npmjs.org/### Debugging with Verbose Output
To see exactly what's happening during the DNS resolution:
npm install --loglevel verboseOr check npm's debug log:
cat ~/.npm/_logs/*-debug.log | tail -100### WSL (Windows Subsystem for Linux)
WSL can have DNS resolution issues. Check if DNS is properly inherited from Windows:
cat /etc/resolv.confIf the nameserver looks wrong, you can configure WSL to generate resolv.conf differently by editing /etc/wsl.conf or manually setting nameservers.
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