NPM self_signed_cert_in_chain

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: SELF_SIGNED_CERT_IN_CHAIN error while using npm install

Also I have tried going through the documentation on NPM's site:

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

2

4 Answers

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="" 

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?.

2

This works for me:

$ export NODE_TLS_REJECT_UNAUTHORIZED=0 $ npm install 
1

Use this command below and it could work fine:

npm config set registry=""

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.

3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like