How to fix npm ERR! code ECONNRESET npm ERR! network tunneling socket could not be established in npm

npmINTERMEDIATEMEDIUMUpdated Dec 6, 2025ยท 166 views

The ECONNRESET error with 'tunneling socket could not be established' occurs when npm cannot connect through a proxy server. This is typically caused by misconfigured proxy settings or network connectivity issues.

Quick fix

Fixes ECONNRESET

# View all npm config
npm config list

# Check specific proxy settings
npm config get proxy
npm config get https-proxy
  1. Check your current proxy configuration
  2. Remove proxy settings if not needed
  3. Configure proxy settings correctly
  4. Verify the proxy is reachable
npm โ€” error
# View all npm config
npm config list
# Check specific proxy settings
npm config get proxy
npm config get https-proxy
npm ERR! code ECONNRESET
npm ERR! network tunneling socket could not be established

What this error means

The "tunneling socket could not be established" error with code ECONNRESET indicates that npm attempted to connect to the npm registry through a proxy server, but the connection was abruptly terminated. The proxy either rejected the connection, timed out, or the network path between your machine and the proxy was interrupted. When npm is configured to use a proxy (either via npm config or environment variables), it creates a tunneling connection to route HTTPS traffic through the proxy server. If this tunnel cannot be established, npm fails with ECONNRESET - meaning the remote end (the proxy) reset the connection before communication could complete. This error is especially common in corporate environments where developers must use proxy servers to access external networks. It can also occur when proxy settings are incorrectly configured, when moving between networks (e.g., from office to home), or when the proxy server itself is experiencing issues.

Typical symptoms

  • npm install fails with 'code ECONNRESET' and 'tunneling socket could not be established'
  • Commands work outside the corporate network but fail inside
  • npm commands hang for a long time before failing with connection errors
  • Error occurs immediately after changing networks or VPN status
  • Other tools using the same proxy work, but npm does not

Common causes

  1. Proxy settings configured in npm but you're not behind a proxy
  2. Incorrect proxy URL, port, or credentials in npm configuration
  3. Environment variables (HTTP_PROXY, HTTPS_PROXY) set incorrectly
  4. Corporate proxy blocking or filtering npm registry traffic
  5. Using HTTPS protocol for proxy URL when HTTP is required
  6. Proxy server is down or unreachable
  7. Firewall or antivirus software blocking npm connections
  8. SSL certificate issues between npm and the proxy

How to fix "npm ERR! code ECONNRESET npm ERR! network tunneling socket could not be established"

1Check your current proxy configuration

First, inspect what proxy settings npm currently has configured:

bash
# View all npm config
npm config list

# Check specific proxy settings
npm config get proxy
npm config get https-proxy

Also check for environment variables:

bash
# Linux/macOS
echo $HTTP_PROXY
echo $HTTPS_PROXY
echo $http_proxy
echo $https_proxy

# Windows (Command Prompt)
echo %HTTP_PROXY%
echo %HTTPS_PROXY%

If you see proxy values but you're not behind a proxy, that's likely the problem.

2Remove proxy settings if not needed

If you're not behind a corporate proxy, remove any proxy configuration:

bash
# Remove npm proxy settings
npm config delete proxy
npm config delete https-proxy

# Also remove http-proxy if set
npm config delete http-proxy

Clear environment variables for the current session:

bash
# Linux/macOS
unset HTTP_PROXY
unset HTTPS_PROXY
unset http_proxy
unset https_proxy

# Windows (Command Prompt)
set HTTP_PROXY=
set HTTPS_PROXY=

Then retry your npm command.

3Configure proxy settings correctly

If you ARE behind a corporate proxy, configure npm with the correct settings:

bash
# Set proxy (use http:// even for https-proxy)
npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080

If your proxy requires authentication:

bash
npm config set proxy http://username:password@proxy.company.com:8080
npm config set https-proxy http://username:password@proxy.company.com:8080

Important: Use http:// (not https://) as the protocol for both proxy settings, even for https-proxy. The proxy connection itself uses HTTP; only the tunneled traffic is HTTPS.

Note: If your password contains special characters like @, :, or %, you need to URL-encode them (e.g., @ becomes %40).

4Verify the proxy is reachable

Test if you can reach the npm registry through your proxy:

bash
# Test direct connection to npm registry
curl -v https://registry.npmjs.org/

# Test through proxy
curl -v --proxy http://proxy.company.com:8080 https://registry.npmjs.org/

If curl works but npm doesn't, the issue is likely in npm's configuration. If curl also fails, the problem is with the proxy or network.

You can also try accessing https://registry.npmjs.org in your browser to verify the registry is accessible.

5Try using HTTP registry (temporary workaround)

If SSL/TLS issues are causing the problem, you can temporarily switch to HTTP:

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

Warning: Using HTTP instead of HTTPS is less secure and should only be used for debugging. Switch back to HTTPS once the issue is resolved:

bash
npm config set registry https://registry.npmjs.org/
6Disable strict SSL if needed

Some corporate proxies perform SSL inspection, which can cause certificate errors. If you trust your network, you can disable strict SSL:

bash
npm config set strict-ssl false

You might also need to set the CA certificate to null:

bash
npm config set cafile null

Security Warning: Disabling SSL verification makes you vulnerable to man-in-the-middle attacks. Only use this in trusted corporate environments and re-enable when possible:

bash
npm config set strict-ssl true
npm config delete cafile
7Clear npm cache and retry

Cached data can sometimes cause connection issues. Clear the cache:

bash
npm cache clean --force

Then delete node_modules and package-lock.json if needed:

bash
rm -rf node_modules package-lock.json
npm install
8Check for conflicting .npmrc files

npm reads configuration from multiple .npmrc files. Check all locations for conflicting settings:

bash
# Project-level
cat .npmrc

# User-level
cat ~/.npmrc

# Global
cat /etc/npmrc  # Linux/macOS
# or
type %APPDATA%\npm\etc\npmrc  # Windows

Remove or comment out any conflicting proxy settings in these files.

9Windows-specific: Disable automatic proxy detection

On Windows 10/11, automatic proxy detection can interfere with npm:

1. Open Settings > Network & Internet > Proxy
2. Turn off Automatically detect settings
3. If you need a proxy, configure it manually instead

After changing these settings, restart your terminal and try npm again.

Advanced notes

### Understanding Proxy Configuration Priority

npm reads proxy configuration from multiple sources in this order (highest priority first):

1. Command-line flags (--proxy)
2. Environment variables (HTTP_PROXY, HTTPS_PROXY)
3. Project .npmrc file
4. User ~/.npmrc file
5. Global /etc/npmrc or built-in defaults

### Using CNTLM for NTLM Proxies

Corporate environments often use NTLM authentication. The cntlm proxy can help:

bash
# Install cntlm
sudo apt-get install cntlm  # Debian/Ubuntu
brew install cntlm  # macOS

# Configure cntlm with your credentials
# Edit /etc/cntlm.conf with your domain, username, and password hash
# Then start cntlm as a local proxy

# Point npm to local cntlm proxy
npm config set proxy http://127.0.0.1:3128
npm config set https-proxy http://127.0.0.1:3128

### VPN Considerations

When connected to a corporate VPN:
- Proxy settings may be required even if not needed on the office network
- DNS resolution might change, affecting how proxy hostnames resolve
- Split tunneling configurations may affect which traffic goes through the proxy

If npm works without VPN but fails with VPN connected, check if your VPN client modifies proxy settings.

### CI/CD Pipeline Configuration

In CI environments, set proxy via environment variables in your pipeline configuration:

yaml
# GitHub Actions example
env:
  HTTP_PROXY: http://proxy.company.com:8080
  HTTPS_PROXY: http://proxy.company.com:8080
  NO_PROXY: localhost,127.0.0.1

### NO_PROXY for Internal Registries

If you use a private npm registry that doesn't require the proxy:

bash
npm config set noproxy "registry.internal.company.com,localhost"
# or via environment variable
export NO_PROXY="registry.internal.company.com,localhost"

Frequently asked questions

What does "ECONNRESET" mean?
The "tunneling socket could not be established" error with code ECONNRESET indicates that npm attempted to connect to the npm registry through a proxy server, but the connection was abruptly terminated. The proxy either rejected the connection, timed out, or the network path between your machine and the proxy was interrupted. When npm is configured to use a proxy (either via npm config or environment variables), it creates a tunneling connection to route HTTPS traffic through the proxy server.
How do I fix "ECONNRESET"?
The ECONNRESET error with 'tunneling socket could not be established' occurs when npm cannot connect through a proxy server. This is typically caused by misconfigured proxy settings or network connectivity issues.
What causes "ECONNRESET"?
Proxy settings configured in npm but you're not behind a proxy Incorrect proxy URL, port, or credentials in npm configuration Environment variables (HTTP_PROXY, HTTPS_PROXY) set incorrectly
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