NPM self_signed_cert_in_chain

node.jsNpmVisual Studio-2015

node.js Problem Overview


I am having issues getting NPM to install properly. I have tried stepping through the instructions on several of the posts here on stack overflow, specifically from this thread: https://stackoverflow.com/questions/24669510/self-signed-cert-in-chain-error-while-using-npm-install

Also I have tried going through the documentation on NPM's site: https://blog.npmjs.org/post/78165272245/more-help-with-self-signed-cert-in-chain-and-npm.html

I am still receiving the error everytime I try to install. please advise.

node.js Solutions


Solution 1 - node.js

If you're behind the corporate proxy (which uses e.g. Blue Coat), you should use http instead of https for repository addresses, e.g.

npm config set registry="http://registry.npmjs.org/"

See: Error: SSL Error: SELF_SIGNED_CERT_IN_CHAIN while using npm.


You can also import failing self-certificate into your system and mark as trusted, or temporary disable SSL validation while installing packages (quick, but not recommended method):

npm config set strict-ssl false

See: Error: SSL Error: SELF_SIGNED_CERT_IN_CHAIN while using npm.


The recommended way (and more painful) is just to point to the right certificate file, e.g.

npm config set cafile "<path to your certificate file>"

See: How to fix SSL certificate error when running Npm on Windows?.

Solution 2 - node.js

This works for me:

$ export NODE_TLS_REJECT_UNAUTHORIZED=0
$ npm install

Solution 3 - node.js

Use this command below and it could work fine:

> npm config set registry="http://registry.npmjs.org/"

Solution 4 - node.js

I know this question has been posted a few years ago. Since it still pops up at the top results on Google, I would like to share my proper and secure solution for this problem.

Solution for one Authority Root certificate

I would like to advise everyone to make sure to keep your connection secured by using the https registry. Also stop disabeling strict-ssl. Many are missing the point here and go for a quick fix instead of the only right solution.

You'll have to add your .pem certificate to the .npmrc file (npm config). When you just need to add one certificate use the following:

npm config set cafile /path/to/cert.pem

Solution for multiple Authority Root certificates

When you're company uses multiple certificates (like mine) you'll first need to combine the certificates to one .pem by entering the following command in your terminal:

cat cert1.pem cert2.pem > cert_combined.pem

Then make sure to point the right .pem file in your .npmrc

npm config set cafile /path/to/cert_combined.pem

Forget the solutions other people mention like ca[]="..." and NODE_EXTRA_CA_CERTS. This solution is tested and verified within a company that uses multiple Authority Root certificates using node v16.13.0 and npm v8.3.0.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionjacobjp52285View Question on Stackoverflow
Solution 1 - node.jskenorbView Answer on Stackoverflow
Solution 2 - node.jsHAltosView Answer on Stackoverflow
Solution 3 - node.jsHigor FelypeView Answer on Stackoverflow
Solution 4 - node.jsM. GroenhoutView Answer on Stackoverflow