How to fix npm ERR! code ERR_SOCKET_TIMEOUT npm ERR! network Socket timeout in npm

npmBEGINNERMEDIUMUpdated Dec 5, 2025ยท 184 views

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
  1. Increase npm timeout configuration
  2. Clear npm cache and lock files
  3. Check and fix proxy settings
  4. Update Node.js and npm
npm โ€” error
nano ~/.npmrc
npm ERR! code ERR_SOCKET_TIMEOUT
npm 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

  1. Network timeout value is too low for your connection speed or current npm registry load
  2. Slow or unstable internet connection causing requests to exceed default 30-60 second timeout
  3. Corporate proxy or firewall blocking or throttling connections to registry.npmjs.org
  4. VPN connection issues (multiple active VPNs, reconnection problems, or bandwidth limitations)
  5. npm registry server overload or temporary service degradation
  6. 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"

1Increase npm timeout configuration

The quickest fix is to increase npm's timeout thresholds. Edit or create a .npmrc file:

bash
nano ~/.npmrc

Add these configuration values:

ini
timeout=600000
fetch-timeout=600000
fetch-retry-mintimeout=20000
fetch-retry-maxtimeout=120000
fetch-retries=5

Alternatively, set these via command line:

bash
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 600000
2Clear npm cache and lock files

Corrupted cache or lock files can trigger socket errors. Clean everything and reinstall:

bash
# 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 install
3Check and fix proxy settings

Corporate networks often require proxy configuration. First, verify your current proxy settings:

bash
# View current proxy settings
npm config get proxy
npm config get https-proxy

If these show incorrect values or you need to set a proxy:

bash
# 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:8080
4Update Node.js and npm

Older versions of npm and Node.js have known timeout issues. Update to the latest LTS versions:

bash
# Check current versions
node --version
npm --version

# Update npm
npm install -g npm@latest

# For Node.js, use nvm:
nvm install 20
nvm use 20

After updating, retry npm install.

5Check VPN and network connectivity

Network and VPN issues are common causes. Verify your connection:

bash
# 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.org

For VPN users:
- Disconnect and reconnect your VPN
- Check if multiple VPN connections are active
- Test if npm install works without VPN

6Try alternative package manager (Yarn)

If npm continues to timeout, Yarn handles slow connections more gracefully:

bash
# Install yarn globally
npm install -g yarn

# Use yarn instead of npm
yarn install

# Or for CI: yarn install --frozen-lockfile

Yarn 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