Maaz Zindani

Loading the index…

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

yarn install fails with AggregateError and ECONNREFUSED

ErrorAggregateError [ECONNREFUSED]

Short answer

Node.js tries every address a host name resolves to, IPv6 and IPv4, and when all of them refuse the connection it raises one AggregateError. During yarn install that means nothing accepted a connection at the address yarn was told to use. In practice it is a proxy setting that points nowhere or a registry set to a server that is down.

  • Applies to Yarn 4, Node.js 22, Node.js 24
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Print the proxy and registry lines from every yarn config file that applies. A local address, or a port nothing listens on, is the cause. The AggregateError lists one failed attempt per address, so read the addresses it prints too.

    grep -n -i -E "proxy|registry" .yarnrc.yml ~/.yarnrc.yml .yarnrc ~/.yarnrc 2>/dev/null
  2. 2Match what you see, then jump to its fix

    1. 1The grep prints an httpProxy or httpsProxy line pointing at a local or unused addressA proxy is configured and nothing listens thereFix
    2. 2npmRegistryServer in a yarn file names a local or private addressThe registry is set to a server that is not runningFix

What does the error look like?

  • AggregateError [ECONNREFUSED]

Cause 1 of 2

A proxy is configured and nothing listens there

1Check

In Yarn 2 and newer the httpProxy and httpsProxy settings in .yarnrc.yml make every request go through that proxy. If the proxy program is stopped, every connection to it is refused.

grep -n -i "proxy" .yarnrc.yml ~/.yarnrc.yml

2Fix

Delete the proxy lines if you do not need them, or start the proxy and point yarn at its real address.

# .yarnrc.yml: remove these lines, or fix the address
httpProxy: "http://proxy:4040"
httpsProxy: "http://proxy:4040"

3Verify

Run the install again.

yarn install

Confirmed by yarnpkg.com

Did this fix it?

Cause 2 of 2

The registry is set to a server that is not running

1Check

The default npmRegistryServer in Yarn 2 and newer is https://registry.yarnpkg.com. A project or user file can replace it with an address that is down, such as a local mirror.

grep -n -i "npmRegistryServer" .yarnrc.yml ~/.yarnrc.yml

2Fix

Delete the override or set the public registry again.

# .yarnrc.yml
npmRegistryServer: "https://registry.yarnpkg.com"

3Verify

The install now runs.

yarn install

Confirmed by yarnpkg.com

Did this fix it?

How do I stop it coming back?

  • Keep proxy and registry settings in the project file only when the project needs them, and review them after a network change.
  • Print yarn config values at the start of a CI job that fails on network errors.
  • Do not leave a local proxy setting in the user-level yarn file after a debugging session.

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

ng serve says it cannot determine the project or target

Cannot determine project for command.

The Angular CLI looked through angular.json for a project that defines the target you asked for (serve, build, test) and found none, or found several and could not pick one.

3 causes, each with a fix

Back end

ng serve cannot find the dev-server builder package

Could not find the implementation for builder @angular/build:dev-server

The builder named in angular.json (for example @angular-devkit/build-angular:dev-server) is looked up as an npm package starting from the workspace root.

3 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.