npm rejects the certificate it gets from a company proxy
npm ERR! code SELF_SIGNED_CERT_IN_CHAINShort 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.
Fix it fast
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:80802Match what you see, then jump to its fix
- 1
SELF_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
npm 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
The 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
- 1
What does the error look like?
npm ERR! code SELF_SIGNED_CERT_IN_CHAINnpm ERR! request to https://registry.npmjs.org/express failed, reason: self signed certificate in certificate chainnpm ERR! code UNABLE_TO_GET_ISSUER_CERT_LOCALLYunable 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-ssl2Fix
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.pem3Verify
The registry answers and an install works.
npm ping
npm install --no-save left-padConfirmed by docs.npmjs.com
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
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.pem3Verify
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 pingConfirmed by nodejs.org
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
Back end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fixBack end
Application Load Balancer returns 502 for a Node.js target
HTTPCode_ELB_502_Count
An ALB returns 502 when the target gives it something it cannot use: a refused or reset connection, a connection closed mid-request, a bad response, or a header over 32 K.
4 causes, each with a fixBack end
Axios call from a React app comes back 404
404 (Not Found)
Status code 404 means a server answered, but it has nothing at that path.
3 causes, each with a fixBack end
bcrypt.hash throws 'data and salt arguments required'
Error: data and hash arguments required
The bcrypt package throws this when hash gets null or undefined for the password or for the salt.
4 causes, each with a fixBack end
bcryptjs rejects hash() or compare() with Illegal arguments
Error: Illegal arguments: string, undefined
bcryptjs checks the types of its two arguments and, when either is wrong, throws Illegal arguments followed by the typeof of the first and the second.
3 causes, each with a fixBack end
Express warns 'body-parser deprecated undefined extended'
body-parser deprecated undefined extended
The warning appears because urlencoded() was called without the extended option, which body-parser 1.x has warned about since version 1.4.0.
3 causes, each with a fix