How to fix npm ERR! ESOCKETTIMEDOUT in npm
The ESOCKETTIMEDOUT error occurs when npm cannot establish or maintain a network connection to the registry within the expected time. This typically indicates network issues, slow connections, or registry unavailability.
Quick fix
Fixes npm ERR! ESOCKETTIMEDOUT
npm config set fetch-timeout 300000
npm config set fetch-retries 5
npm config set fetch-retry-mintimeout 20000
npm config set fetch-retry-maxtimeout 120000- Increase npm timeout settings
- Test registry connectivity
- Try a different registry mirror
- Check proxy and VPN settings
npm config set fetch-timeout 300000npm config set fetch-retries 5npm config set fetch-retry-mintimeout 20000npm config set fetch-retry-maxtimeout 120000npm ERR! ESOCKETTIMEDOUT
What this error means
ESOCKETTIMEDOUT means npm's network socket connection timed out while trying to communicate with the npm registry or another remote server. Unlike ETIMEDOUT which occurs during connection establishment, ESOCKETTIMEDOUT typically happens when a connection was established but the data transfer took too long. This error indicates that while npm was able to start a connection, the remote server stopped responding during the data exchange, or the network became too slow to complete the transfer within the allowed timeout period.
Typical symptoms
- npm install hangs for a long time before failing
- Error appears after partial package downloads
- Intermittent failures on large package installations
- CI/CD pipelines timeout during npm install
- Problem worsens with slower network connections
- Multiple retry attempts eventually succeed
Common causes
- Slow or unstable network connection
- npm registry server experiencing high load
- Corporate proxy or firewall throttling connections
- Large packages taking too long to download
- VPN connection causing latency issues
- DNS resolution delays
- ISP network congestion
How to fix "npm ERR! ESOCKETTIMEDOUT"
Extend the default timeout to allow more time for slow connections:
npm config set fetch-timeout 300000
npm config set fetch-retries 5
npm config set fetch-retry-mintimeout 20000
npm config set fetch-retry-maxtimeout 120000Check if you can reach the npm registry:
npm ping
curl -I https://registry.npmjs.orgIf these fail, the issue is network-related.
Use an alternative registry or mirror closer to your location:
# Use a mirror temporarily
npm install --registry https://registry.npmmirror.com
# Or set permanently
npm config set registry https://registry.npmmirror.comIf behind a proxy, ensure npm is configured correctly:
npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080Try disconnecting from VPN if possible.
A corrupted cache can cause connection issues:
npm cache clean --force
rm -rf node_modules package-lock.json
npm installFor large projects, install dependencies in groups:
npm install package1 package2
npm install package3 package4
# Continue until all installedAdvanced notes
In CI/CD environments, consider using npm ci with increased timeouts and retry logic. Docker builds may need --network-timeout flags. For corporate networks, work with IT to whitelist registry.npmjs.org and its CDN endpoints. Consider using a local npm proxy like Verdaccio or Nexus for frequently used packages to reduce external network dependency.
Frequently asked questions
- What does "npm ERR! ESOCKETTIMEDOUT" mean?
- ESOCKETTIMEDOUT means npm's network socket connection timed out while trying to communicate with the npm registry or another remote server. Unlike ETIMEDOUT which occurs during connection establishment, ESOCKETTIMEDOUT typically happens when a connection was established but the data transfer took too long. This error indicates that while npm was able to start a connection, the remote server stopped responding during the data exchange, or the network became too slow to complete the transfer within the allowed timeout period.
- How do I fix "npm ERR! ESOCKETTIMEDOUT"?
- The ESOCKETTIMEDOUT error occurs when npm cannot establish or maintain a network connection to the registry within the expected time. This typically indicates network issues, slow connections, or registry unavailability.
- What causes "npm ERR! ESOCKETTIMEDOUT"?
- Slow or unstable network connection npm registry server experiencing high load Corporate proxy or firewall throttling connections
- Is the "npm ERR! ESOCKETTIMEDOUT" 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+timeout(Stack Overflow)