Skip to content
ecdsa.com
npm (Node.js)Package managers

Error message

npm error code CERT_HAS_EXPIRED

Also printed as

  • npm ERR! code CERT_HAS_EXPIRED
  • npm error request to https://registry.example.com/lodash failed, reason: certificate has expired

npm 10 and later print "npm error code CERT_HAS_EXPIRED"; npm 9 and older "npm ERR! code CERT_HAS_EXPIRED". The following lines give the URL with "reason: certificate has expired".

npm (Node.js) — registry request over HTTPS

What it means

A certificate in the chain npm received from the registry (or from a proxy in between) is past its expiry date by this machine's clock. For the public registry this almost never means npm's own certificate expired: it points to an old CA pinned in your npm configuration, an outdated Node.js root list, a proxy certificate, or a wrong clock. For private registries, the server's certificate may really have expired.

Why it happens

How to fix it

  1. 1.

    Check which registry and certificate are involved

    Read the configured registry and the end date of the certificate it serves. An expired certificate on a private registry must be renewed on the server.

    bash
    npm config get registry
    echo | openssl s_client -connect registry.example.com:443 -servername registry.example.com 2>/dev/null \
      | openssl x509 -noout -subject -enddate
  2. 2.

    Remove stale ca or cafile settings

    npm config list shows settings from every .npmrc level; delete ca or cafile entries that point to old certificates (or update the file they reference).

    bash
    # An old CA pinned in .npmrc replaces the default roots: list and remove it
    npm config list | grep -E '^;? *(ca|cafile)'
    npm config delete ca
    npm config delete cafile
  3. 3.

    Upgrade Node.js and npm

    A maintained Node.js release brings a current root list; upgrade npm afterwards.

    bash
    node -v && npm -v   # Node.js bundles its root list; very old releases carry expired roots
    # upgrade Node.js to a maintained release (nvm, fnm, volta or your OS packages), then:
    npm install -g npm@latest

Related errors

Browse the full signature error database