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

Error message

npm error code SELF_SIGNED_CERT_IN_CHAIN

Also printed as

  • npm ERR! code SELF_SIGNED_CERT_IN_CHAIN
  • npm error request to https://registry.example.com/lodash failed, reason: self-signed certificate in certificate chain

npm 10 and later print "npm error code SELF_SIGNED_CERT_IN_CHAIN"; npm 9 and older "npm ERR! code SELF_SIGNED_CERT_IN_CHAIN". The next lines repeat the code as errno and name the URL with "reason: self-signed certificate in certificate chain".

npm (Node.js) — registry request over HTTPS

What it means

The registry connection presented a certificate chain that ends in a self-signed root unknown to Node.js. For registry.npmjs.org this means the traffic is being intercepted and re-signed, almost always by a company proxy or an antivirus product with HTTPS scanning, whose root the browser trusts but npm does not.

Why it happens

How to fix it

  1. 1.

    Give npm the proxy's root with cafile

    Export the root certificate (from your IT team or the OS trust store) as PEM and set it as npm's cafile. npm then trusts only the CAs in that file, so on laptops that also work off the company network, add the public roots to the same file or prefer NODE_EXTRA_CA_CERTS.

    bash
    npm config set cafile /etc/ssl/private-ca/corp-proxy-root.pem
    npm install
  2. 2.

    Or set NODE_EXTRA_CA_CERTS

    Adds the root for npm and every other Node.js tool without replacing Node.js's public roots. On Windows, set it as a user environment variable and open a new terminal.

    bash
    # Windows (PowerShell): setx NODE_EXTRA_CA_CERTS C:\certs\corp-proxy-root.pem
    export NODE_EXTRA_CA_CERTS=/etc/ssl/private-ca/corp-proxy-root.pem
    npm install
  3. 3.

    Or let Node.js use the OS store

    NODE_USE_SYSTEM_CA=1 makes Node.js (and npm) trust what the operating system trusts, which on managed machines includes the proxy root.

    bash
    # Managed machines already trust the proxy root in the OS store
    NODE_USE_SYSTEM_CA=1 npm install
  4. 4.

    Temporary diagnostic: --strict-ssl=false

    Only to confirm that trust is the issue. Packages run install scripts, so accepting unverified downloads is how supply-chain attacks get onto developer machines; never put strict-ssl=false in .npmrc.

    bash
    # Temporary diagnostic for one command only
    npm install --strict-ssl=false

Related errors

Browse the full signature error database