Skip to content
Latchkey

npm ECONNREFUSED "connect ECONNREFUSED" - Fix Registry Connection Refused

ECONNREFUSED means something answered the connection attempt with an active refusal - nothing is listening on that host/port. Unlike a timeout, the network reached the target and was told "no".

What this error means

npm install fails with connect ECONNREFUSED and an IP:port. It frequently points at 127.0.0.1 or an internal mirror address, meaning the configured registry or proxy is down or on the wrong port.

npm output
npm error code ECONNREFUSED
npm error syscall connect
npm error errno ECONNREFUSED
npm error request to http://127.0.0.1:4873/lodash failed,
reason: connect ECONNREFUSED 127.0.0.1:4873

Common causes

A local or internal mirror is not running

An .npmrc pointing at a local registry proxy (e.g. Verdaccio on 127.0.0.1:4873) gets refused when that service is not started in CI.

Wrong proxy host or port

A proxy/https-proxy setting pointing at a port nothing listens on causes every request to be refused immediately.

How to fix it

Point npm at a reachable registry

Verify the registry/proxy address and that the service is actually up.

Terminal
npm config get registry
npm config get proxy
# fall back to the public registry if the mirror is down
npm config set registry https://registry.npmjs.org/
npm ci

Bring up or bypass the mirror

  1. Ensure any local registry proxy is started before npm ci in the job.
  2. Clear stale proxy/https-proxy settings if no proxy is needed.
  3. Confirm the mirror listens on the host/port your .npmrc references.

How to prevent it

  • Start internal mirrors before the install step.
  • Keep proxy settings accurate or unset.
  • Have a public-registry fallback for mirror outages.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →