cacheport

Error · npm

Fixing npm ERR! code ETIMEDOUT in CI

npm opened a connection to the registry, or tried to, and gave up waiting. The registry, the network in between or a proxy did not answer within npm's timeout. The package itself is fine; the request never completed.

What you see

build log
npm ERR! code ETIMEDOUT
npm ERR! errno ETIMEDOUT
npm ERR! network request to https://registry.npmjs.org/react failed, reason: connect ETIMEDOUT 104.16.0.35:443
npm ERR! network This is a problem related to network connectivity.

Common causes

  • A slow or congested path between the runner and registry.npmjs.org, common on shared and self-hosted runners.
  • A corporate proxy or firewall that npm is not configured to use.
  • IPv6 routes that are advertised but do not work, so connections hang before falling back to IPv4.
  • Large installs that open hundreds of connections at once.

How to fix it

  1. 01

    Give npm more patience

    Raise the fetch timeout and retry count. This hides short hiccups but makes slow builds slower.

    .npmrc
    fetch-retries=5
    fetch-retry-mintimeout=20000
    fetch-retry-maxtimeout=120000
    fetch-timeout=300000
  2. 02

    Tell npm about your proxy

    If the runner sits behind a proxy, npm needs to know it.

    shell
    npm config set proxy http://proxy.internal:3128
    npm config set https-proxy http://proxy.internal:3128
  3. 03

    Fetch from a cache near the runner

    Move the registry closer. With a registry cache in the same region, packages already pulled once never cross the slow path again.

    .npmrc
    registry=https://acme.cacheport.cc/npm/
    //acme.cacheport.cc/npm/:_authToken=${CACHEPORT_TOKEN}

Other network failures in builds

Start on the free plan

20 GB of cache, every registry, unlimited users. Upgrade when your pipelines outgrow it.