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