Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

npm install keeps dropping the connection with ECONNRESET

Errornpm ERR! code ECONNRESET

Short answer

ECONNRESET means the other end of the connection closed it while npm was still reading. For npm that is the registry, or a proxy sitting in front of it. First run npm ping. If it fails, look at the proxy and registry settings in your npm config. If it passes, the link is unstable: raise the retry and timeout settings.

  • Applies to npm 10, Node.js 22, Ubuntu 24.04, Windows 11
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Ask npm to reach the registry it is configured to use. A failure here points at the proxy or registry setting; a pass points at a flaky connection.

    npm ping
    npm config get registry
  2. 2Match what you see, then jump to its fix

    1. 1npm ping fails, and npm config get proxy or https-proxy prints a URL you do not rememberA proxy is set in npm config and it resets the connectionFix
    2. 2npm config get registry prints something other than https://registry.npmjs.org/The registry setting points at a mirror or host that is downFix
    3. 3npm ping passes, yet npm install fails part-way and fails at a different package each timeThe connection is unstable and npm gives up too earlyFix

What does the error look like?

  • npm ERR! code ECONNRESET
  • npm ERR! network read ECONNRESET
  • npm ERR! network This is a problem related to network connectivity.

Cause 1 of 3

A proxy is set in npm config and it resets the connection

1Check

npm sends HTTP and HTTPS requests through the proxy and https-proxy settings, and also honours the HTTP_PROXY and HTTPS_PROXY environment variables. An old or wrong proxy address left in .npmrc is a common leftover.

npm config get proxy
npm config get https-proxy
npm config get noproxy

2Fix

If you are not meant to use a proxy, remove both settings. If you are, correct the address, and list hosts that must skip it in noproxy.

npm config delete proxy
npm config delete https-proxy

3Verify

npm can reach the registry again.

npm ping

Confirmed by docs.npmjs.com

Did this fix it?

Cause 2 of 3

The registry setting points at a mirror or host that is down

1Check

The registry setting is the base URL for every package request. A company mirror, or a mirror left behind by an earlier setup, that drops connections will fail the same way.

npm config get registry

2Fix

Set the registry back to the default, or to a mirror that is working.

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

3Verify

npm ping reports a PONG with a response time.

npm ping

Confirmed by docs.npmjs.com

Did this fix it?

Cause 3 of 3

The connection is unstable and npm gives up too early

1Check

Node.js describes ECONNRESET as a connection forcibly closed by the peer, usually from a lost connection, timeout or reboot on the remote socket. By default npm retries a failed fetch only 2 times. On a weak link that is not enough.

npm config get fetch-retries
npm config get fetch-timeout
npm config get maxsockets

2Fix

Allow more retries with longer waits between them. Lowering maxsockets (default 15) also opens fewer parallel connections, which helps on a link that drops under load.

npm config set fetch-retries=5
npm config set fetch-retry-mintimeout=20000
npm config set fetch-retry-maxtimeout=120000
npm config set maxsockets=5

3Verify

Run the install again.

npm install

Confirmed by docs.npmjs.com

Did this fix it?

How do I stop it coming back?

  • Keep proxy and registry settings in the project .npmrc only when the team really needs them, and review them when you change network.
  • On CI, set the retry and timeout values once in the pipeline config so a brief network blip does not fail a build.
  • Run npm ping first when an install fails: it separates a network problem from a package problem in seconds.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

npm install times out or never finishes

npm install does not finish and prints nothing for minutes

npm install waits for the registry, retries a few times, then gives up.

4 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.