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 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:4873Common 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.
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 ciBring up or bypass the mirror
- Ensure any local registry proxy is started before
npm ciin the job. - Clear stale
proxy/https-proxysettings if no proxy is needed. - Confirm the mirror listens on the host/port your
.npmrcreferences.
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.