Maaz Zindani

Loading the index…

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

npm rejects the certificate it gets from a company proxy

Errornpm ERR! code SELF_SIGNED_CERT_IN_CHAIN

Short answer

A proxy that inspects HTTPS traffic re-signs it with the company's own root certificate, which Node does not know, so npm refuses the connection. Give npm that root certificate with the cafile setting, or Node with NODE_EXTRA_CA_CERTS. Setting strict-ssl=false also removes the error, but it switches off the check that protects your packages.

  • Applies to npm 10 and 11, Node.js 22 and 24, OpenSSL 3, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Look at who signed the certificate that the registry connection really returns. If the issuer is your company or a security product (not a public authority), a proxy is re-signing the traffic, and that issuer's root certificate is what npm needs.

    openssl s_client -connect registry.npmjs.org:443 -servername registry.npmjs.org -showcerts </dev/null 2>/dev/null | grep -E ' s:| i:'
    # behind an HTTP proxy, add:  -proxy proxy.example.com:8080
  2. 2Match what you see, then jump to its fix

    1. 1SELF_SIGNED_CERT_IN_CHAIN, and the issuer printed above is your company or a filtering productThe proxy's root certificate is missing from npm's trust listFix
    2. 2npm install succeeds after cafile, but a node script, npx tool or build step still reports the same certificate errorOther Node.js tools fail even though npm now worksFix
    3. 3The error stays the same after setting cafile, or Node prints a warning about the file, or UNABLE_TO_GET_ISSUER_CERT_LOCALLY keeps appearingThe certificate file is in the wrong format or incompleteFix

What does the error look like?

  • npm ERR! code SELF_SIGNED_CERT_IN_CHAIN
  • npm ERR! request to https://registry.npmjs.org/express failed, reason: self signed certificate in certificate chain
  • npm ERR! code UNABLE_TO_GET_ISSUER_CERT_LOCALLY
  • unable to get local issuer certificate

Cause 1 of 3

The proxy's root certificate is missing from npm's trust list

1Check

npm trusts the public authorities it ships with. A TLS-inspecting proxy answers with a certificate signed by its own root, which is not among them. Check whether a certificate file is configured already.

npm config get cafile
npm config get strict-ssl

2Fix

Ask IT for the company root certificate in PEM format (a text file that begins with BEGIN CERTIFICATE) and point npm at it. A cafile may hold several certificates, but it takes the place of npm's default list for registry connections, so include every authority npm must reach, not only the company root.

npm config set cafile /etc/ssl/corp/company-root.pem

3Verify

The registry answers and an install works.

npm ping
npm install --no-save left-pad

Confirmed by docs.npmjs.com

Did this fix it?

Cause 2 of 3

Other Node.js tools fail even though npm now works

1Check

The cafile setting is read by npm only. Any other program started with node uses Node's own list. NODE_EXTRA_CA_CERTS adds your file to that list, and it is read once when the process starts.

echo "$NODE_EXTRA_CA_CERTS"

2Fix

Export the variable in the shell profile (or the service environment) so every Node.js process starts with it. The file must be PEM. Unlike a custom ca option, it extends the well-known roots instead of replacing them.

export NODE_EXTRA_CA_CERTS=/etc/ssl/corp/company-root.pem
# Windows PowerShell
# setx NODE_EXTRA_CA_CERTS "C:\certs\company-root.pem"

3Verify

A new shell starts Node.js with the variable set; a request to an inspected site works.

node -e "fetch('https://registry.npmjs.org/express').then(r => console.log(r.status))"

Confirmed by nodejs.org

Did this fix it?

Cause 3 of 3

The certificate file is in the wrong format or incomplete

1Check

Node expects PEM. If the file is DER (.cer or .crt in binary form), the command below fails. Also compare the issuer of what the proxy sends with the subject of the file you configured: they must lead to the same root.

openssl x509 -in /etc/ssl/corp/company-root.pem -noout -subject -issuer
openssl s_client -connect registry.npmjs.org:443 -servername registry.npmjs.org -showcerts </dev/null 2>/dev/null | grep -E ' s:| i:'

2Fix

Convert a DER file to PEM, and export the root of the chain the proxy actually sends. If the chain also has an intermediate certificate that the proxy does not send, add it to the same file.

openssl x509 -inform DER -in company-root.cer -out company-root.pem

3Verify

openssl prints the subject and issuer for the new file without an error, then npm ping works.

openssl x509 -in company-root.pem -noout -subject
npm ping

Confirmed by nodejs.org

Did this fix it?

How do I stop it coming back?

  • Keep strict-ssl at its default (true); a config that says false is a bug to remove, not a setting to copy between machines.
  • Store the company root in one shared path and set both cafile and NODE_EXTRA_CA_CERTS from your provisioning script.
  • In CI images, add the certificate at build time instead of per job.
  • When the proxy's certificate is replaced, update the PEM file; an expired root brings the error back.

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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.