How to fix npm ERR! code ERR_SOCKET_TIMEOUT npm ERR! network Socket timeout in npm
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.
Quick fix
Fixes ERR_SOCKET_TIMEOUT
nano ~/.npmrc- Increase npm timeout configuration
- Clear npm cache and lock files
- Check and fix proxy settings
- Update Node.js and npm
nano ~/.npmrcnpm ERR! code ERR_SOCKET_TIMEOUTnpm ERR! network Socket timeout
What this error means
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.
Typical symptoms
- npm install, npm ci, or npm update fails partway through downloading packages
- Error message shows 'ERR_SOCKET_TIMEOUT' with no specific package or takes unusually long before failing
- Installation works intermittently on the same machine or network
- Docker builds fail during the npm install stage while local machine works fine
- Corporate network users experience timeouts while personal networks do not
Common causes
- Network timeout value is too low for your connection speed or current npm registry load
- Slow or unstable internet connection causing requests to exceed default 30-60 second timeout
- Corporate proxy or firewall blocking or throttling connections to registry.npmjs.org
- VPN connection issues (multiple active VPNs, reconnection problems, or bandwidth limitations)
- npm registry server overload or temporary service degradation
- DNS resolution delays or network routing problems causing connection establishment delays
How to fix "npm ERR! code ERR_SOCKET_TIMEOUT npm ERR! network Socket timeout"
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.
Advanced notes
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.
Frequently asked questions
- What does "ERR_SOCKET_TIMEOUT" mean?
- 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.
- How do I fix "ERR_SOCKET_TIMEOUT"?
- 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.
- What causes "ERR_SOCKET_TIMEOUT"?
- Network timeout value is too low for your connection speed or current npm registry load Slow or unstable internet connection causing requests to exceed default 30-60 second timeout Corporate proxy or firewall blocking or throttling connections to registry.npmjs.org
- Is the "ERR_SOCKET_TIMEOUT" 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
- ๐Docs: npm config reference(Official Docs)
- ๐ฌSO: npm socket timeout(Stack Overflow)
- ๐GitHub: npm issues(GitHub)