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 notice access token expired or revoked. Please try logging in again.
Token has expired - npm authentication failure
npm ERR! code EAI_AGAIN
How to fix "EAI_AGAIN" in npm
npm error code E403 npm error 403 Forbidden - PUT https://registry.npmjs.org/<package>
How to fix 'E403 Forbidden' error in npm
npm ERR! code EUSAGE npm ERR! Usage error
How to fix "npm ERR! code EUSAGE" in Node.js projects
npm ERR! code E401 npm ERR! 401 Unauthorized
How to fix "E401 Unauthorized" in npm