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.
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.
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 installedIn 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.
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