ERR_SOCKET_TIMEOUT occurs when npm fails to download packages because the network connection exceeded the timeout threshold. Increase timeout settings, check proxy configuration, or try a different network.
The ERR_SOCKET_TIMEOUT error occurs when npm fails to download packages or dependencies because the network connection to the npm registry took too long to respond. This is a network connectivity issue where the request exceeded the default timeout threshold before npm received a response. The timeout can be triggered by slow internet connections, network congestion, proxy configurations, firewall rules, VPN issues, or an overloaded npm registry server.
The quickest fix is to increase npm's timeout thresholds. Edit or create a .npmrc file:
nano ~/.npmrcAdd these configuration values:
timeout=600000
fetch-timeout=600000
fetch-retry-mintimeout=20000
fetch-retry-maxtimeout=120000
fetch-retries=5Alternatively, set these via command line:
npm config set fetch-retry-mintimeout 20000
npm config set fetch-retry-maxtimeout 120000
npm config set fetch-retries 5
npm config set fetch-timeout 600000Corrupted cache or lock files can trigger socket errors. Clean everything and reinstall:
# Clear npm cache completely
npm cache clean --force
# Remove lock file and node_modules
rm package-lock.json
rm -rf node_modules
# Reinstall dependencies
npm installCorporate networks often require proxy configuration. First, verify your current proxy settings:
# View current proxy settings
npm config get proxy
npm config get https-proxyIf these show incorrect values or you need to set a proxy:
# Remove incorrect proxy settings
npm config rm proxy
npm config rm https-proxy
# Set correct proxy (replace with your corporate proxy)
npm config set proxy http://proxy.example.com:8080
npm config set https-proxy http://proxy.example.com:8080Older versions of npm and Node.js have known timeout issues. Update to the latest LTS versions:
# Check current versions
node --version
npm --version
# Update npm
npm install -g npm@latest
# For Node.js, use nvm:
nvm install 20
nvm use 20After updating, retry npm install.
Network and VPN issues are common causes. Verify your connection:
# Test basic connectivity to npm registry
ping registry.npmjs.org
# Test DNS resolution
nslookup registry.npmjs.org
# Test actual connection with curl
curl -I https://registry.npmjs.orgFor VPN users:
- Disconnect and reconnect your VPN
- Check if multiple VPN connections are active
- Test if npm install works without VPN
If npm continues to timeout, Yarn handles slow connections more gracefully:
# Install yarn globally
npm install -g yarn
# Use yarn instead of npm
yarn install
# Or for CI: yarn install --frozen-lockfileYarn automatically retries failed downloads and resumes from where it left off.
The ERR_SOCKET_TIMEOUT error becomes more likely with large dependency trees. On Docker builds, ensure you COPY package-lock.json before running npm install to reduce download time. For CI/CD pipelines, use npm ci instead of npm install for better reliability. If errors persist, contact your ISP or network team to check for latency issues. Consider using a private npm registry mirror if you're in a region with poor npm registry latency.
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