How to fix npm ERR! code ECONNRESET npm ERR! network socket hang up npm ERR! network This is a problem related to network connectivity. in npm

npmINTERMEDIATEMEDIUMUpdated Dec 6, 2025· 4,812 views

This error occurs when the TCP connection to the npm registry is unexpectedly terminated. Common causes include network instability, proxy misconfiguration, firewall interference, or server-side timeouts during package downloads.

Quick fix

Fixes ECONNRESET

npm install
  1. Retry the command
  2. Clear npm cache
  3. Increase network timeouts
  4. Switch to a different registry or mirror
npm — error
npm install
npm ERR! code ECONNRESET
npm ERR! network socket hang up
npm ERR! network This is a problem related to network connectivity.
shell
npm install

What this error means

The ECONNRESET error in npm indicates that the network connection was abruptly closed by the remote server or an intermediate network device. "ECONNRESET" stands for "Error: Connection Reset" and means the TCP socket was forcibly closed before the data transfer completed. When npm downloads packages, it establishes TCP connections to the registry (usually registry.npmjs.org). If any device in the network path—your firewall, corporate proxy, ISP, or the registry itself—terminates the connection unexpectedly, npm receives a "socket hang up" error. This error is particularly frustrating because it often appears intermittently. The same `npm install` command might work on retry, fail again, then succeed—depending on network conditions, server load, and timing. It's especially common in corporate networks with aggressive proxy timeouts, in CI/CD environments with concurrent builds, and on unstable network connections.

Typical symptoms

  • npm install fails randomly with ECONNRESET but succeeds on retry
  • Error appears more frequently when installing large packages
  • Package downloads hang for a while before failing with socket hang up
  • npm commands work fine on home network but fail at office
  • CI/CD pipelines fail intermittently during npm install step
  • Error occurs more often during peak hours or with many concurrent builds
  • WSL2 installations experience more frequent ECONNRESET errors than native Windows/Linux

Common causes

  1. Network instability or intermittent connection drops (most common)
  2. Corporate proxy or firewall terminating idle connections
  3. npm registry server timeout under high load
  4. Keep-alive connection timeout mismatch between client and server
  5. DNS resolution issues causing connection to wrong or overloaded server
  6. VPN connection instability or reconnection during download
  7. WSL2 networking issues with Windows host
  8. Node.js version incompatibility with newer TLS requirements
  9. Antivirus or security software intercepting HTTPS connections

How to fix "npm ERR! code ECONNRESET npm ERR! network socket hang up npm ERR! network This is a problem related to network connectivity."

1Retry the command

ECONNRESET is often a transient network issue. Simply retry your npm command:

bash
npm install

If it works on retry, you experienced a temporary network hiccup. For more reliable installs, consider implementing automatic retries (covered in Advanced Notes).

2Clear npm cache

Corrupted cache data can sometimes cause connection issues during verification:

bash
npm cache clean --force

Then retry your install:

bash
npm install

This ensures npm downloads fresh package data rather than relying on potentially corrupted cached files.

3Increase network timeouts

By default, npm has relatively short timeouts. For slow or unstable networks, increase them:

bash
# Set fetch timeout to 5 minutes (300000ms)
npm config set fetch-timeout 300000

# Set fetch retry max wait to 2 minutes
npm config set fetch-retry-maxtimeout 120000

# Increase minimum timeout between retries
npm config set fetch-retry-mintimeout 20000

# Increase number of retries
npm config set fetch-retries 5

These settings persist in your ~/.npmrc file. Verify with:

bash
npm config list
4Switch to a different registry or mirror

If the main npm registry is experiencing issues, try a regional mirror:

bash
# Use the Cloudflare-backed npm mirror
npm config set registry https://registry.npmmirror.com/

# Or try the Yarn registry (compatible with npm)
npm config set registry https://registry.yarnpkg.com/

To revert to the default registry:

bash
npm config set registry https://registry.npmjs.org/

For China-based developers, the npmmirror (formerly cnpm/taobao) registry often provides faster, more stable connections.

5Check and configure proxy settings

If you're behind a corporate proxy, ensure npm is configured correctly:

bash
# Set HTTP proxy
npm config set proxy http://proxy.company.com:8080

# Set HTTPS proxy
npm config set https-proxy http://proxy.company.com:8080

# If your proxy requires authentication
npm config set proxy http://username:password@proxy.company.com:8080
npm config set https-proxy http://username:password@proxy.company.com:8080

If you're NOT behind a proxy but have old proxy settings:

bash
npm config delete proxy
npm config delete https-proxy

Also check environment variables:

bash
echo $HTTP_PROXY
echo $HTTPS_PROXY
echo $NO_PROXY
6Disable strict SSL (temporary workaround)

Warning: Only use this temporarily for debugging. It reduces security.

Some corporate proxies perform SSL inspection that can interfere with npm:

bash
npm config set strict-ssl false

If this fixes the issue, work with your IT department to properly configure SSL certificates instead of leaving this disabled. To re-enable:

bash
npm config set strict-ssl true
7Update Node.js and npm

Older versions of Node.js may have networking bugs or use outdated TLS versions:

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

Update to Node.js 18.16.0+ or the latest LTS version. Use a version manager for easy switching:

Using nvm (macOS/Linux):

bash
nvm install --lts
nvm use --lts

Using nvm-windows:

powershell
nvm install lts
nvm use lts

After updating Node.js, npm is automatically updated. For a manual npm update:

bash
npm install -g npm@latest
8Fix WSL2 networking issues

WSL2 has known networking issues that can cause ECONNRESET errors more frequently. Try these fixes:

Reset WSL networking:

powershell
# In Windows PowerShell (Admin)
wsl --shutdown
netsh winsock reset
netsh int ip reset

Then restart WSL.

Use a custom DNS in WSL:

bash
# In WSL, edit resolv.conf
sudo rm /etc/resolv.conf
echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf
sudo chattr +i /etc/resolv.conf

Disable generateResolvConf (prevents WSL from overwriting):
Add to /etc/wsl.conf:

ini
[network]
generateResolvConf = false
9Check firewall and antivirus

Security software can interfere with npm's network connections:

Windows Defender/Firewall:
- Temporarily disable and test if npm works
- If so, add Node.js to the firewall exceptions

Corporate firewalls:
- Ensure ports 80 and 443 are open for registry.npmjs.org
- Check if your firewall blocks long-running HTTPS connections

Antivirus (Norton, Kaspersky, etc.):
- Temporarily disable web protection
- Add npm cache directory to exclusions: ~/.npm
- Add node and npm executables to exclusions

Advanced notes

### Automatic Retry Logic for CI/CD

For CI/CD pipelines, implement retry logic to handle transient ECONNRESET errors:

GitHub Actions:

yaml
- name: Install dependencies with retry
  uses: nick-fields/retry@v2
  with:
    timeout_minutes: 10
    max_attempts: 3
    retry_wait_seconds: 30
    command: npm ci

Bash script with exponential backoff:

bash
#!/bin/bash
max_attempts=5
attempt=1
while [ $attempt -le $max_attempts ]; do
  echo "Attempt $attempt of $max_attempts"
  npm install && break
  attempt=$((attempt + 1))
  sleep $((2 ** attempt))
done

### Docker DNS Issues

Docker containers can experience DNS issues leading to ECONNRESET:

dockerfile
# Use Google DNS in Docker
RUN echo "nameserver 8.8.8.8" > /etc/resolv.conf

Or in docker-compose.yml:

yaml
services:
  app:
    dns:
      - 8.8.8.8
      - 8.8.4.4

### IPv6 Issues

Some networks have problematic IPv6 configurations. Force IPv4:

bash
npm config set prefer-offline false
npm config set prefer-online true

Or set Node.js to prefer IPv4:

bash
export NODE_OPTIONS="--dns-result-order=ipv4first"
npm install

### maxsockets Configuration

Reduce concurrent connections to avoid overwhelming proxies or firewalls:

bash
npm config set maxsockets 3

Default is 15. Lower values reduce bandwidth but improve stability on constrained networks.

### macOS Keychain Conflicts

On macOS, the Keychain can sometimes interfere with npm authentication:

bash
# Remove npm credentials from Keychain
security delete-internet-password -s registry.npmjs.org

### Debugging Network Issues

Enable verbose logging to diagnose connection problems:

bash
npm install --loglevel verbose 2>&1 | tee npm-debug.log

Or check the npm debug log:

bash
cat ~/.npm/_logs/*-debug-*.log

### Using Yarn or pnpm as Alternatives

If ECONNRESET persists with npm, alternative package managers may have better networking:

bash
# Yarn
corepack enable
yarn install

# pnpm (often faster and more reliable)
npm install -g pnpm
pnpm install

Both have different networking implementations that may work better in your environment.

Frequently asked questions

What does "ECONNRESET" mean?
The ECONNRESET error in npm indicates that the network connection was abruptly closed by the remote server or an intermediate network device. "ECONNRESET" stands for "Error: Connection Reset" and means the TCP socket was forcibly closed before the data transfer completed. org).
How do I fix "ECONNRESET"?
This error occurs when the TCP connection to the npm registry is unexpectedly terminated. Common causes include network instability, proxy misconfiguration, firewall interference, or server-side timeouts during package downloads.
What causes "ECONNRESET"?
Network instability or intermittent connection drops (most common) Corporate proxy or firewall terminating idle connections npm registry server timeout under high load
Is the "ECONNRESET" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading