可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I'm new to nodejs and npm. I'm trying to install log4js and this is the command for the install:
npm install log4js
I'm running this from Windows Command Line and I after a while of a marker spinning I get the following error:
npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "log4js"
npm ERR! node v0.12.0
npm ERR! npm v2.5.1
npm ERR! code SELF_SIGNED_CERT_IN_CHAIN
npm ERR! self signed certificate in certificate chain
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <http://github.com/npm/npm/issues>
npm ERR! Please include the following file with any support request:
npm ERR! C:\srv\npm-debug.log
I tried doing npm config set ca=""
like suggested here: http://blog.npmjs.org/post/78085451721/npms-self-signed-certificate-is-no-more but I'm still getting this error.
How can I solve this and install NPMs ?
回答1:
Use following command to disable strict ssl-mode and you will not get the error:
npm set strict-ssl false
回答2:
I had the same problem on windows 10.
open windows powerShell and enter the following command:
npm config set registry http://registry.npmjs.org/
Then you can use:
npm install [your package]
回答3:
I'm new to npm as well. Besides the commands mentioned in your link I tried the following and it resolved my issues:
- npm set strict-ssl false
- disabled McAfee temporarily
Reference: Npm SELF_SIGNED_CERT_IN_CHAIN on Azure
回答4:
As metioned by Akshay Vijay Jain above,
npm config set strict-ssl false
TURNING OFF SSL BEFORE INSTALLING THE LATEST VERSION
Then install the latest version
npm install -g npm@latest
INSTALL SUCCESS!!
See the screenshots added for clarity.
回答5:
While setting StrictSsl to false is an option, it compromises your npm security. I recommend not disabling it. The following instructions elaborate on Shreedhar's post to use the cafile. Though it's written from a Windows 10 machine perspective it can be adapted.
Our company uses SSL Inpsection via a proxy, so at the very least we need to include the SSL Inspection certificate. The following instructions assume you are able to use a modern web browser on the machine you are trying to use an externally reaching npm function.
- From a command console, run the following:
npm config list
- Record the value for metrics-registry. This should be a URL.
- Open a browser to the URL. As of writing this answer, it is https://registry.npmjs.org/
- Open the certificate information for the site. For Chrome on Windows, this involves clicking the padlock icon to the left of the URL in the address bar and selecting the option Certificate.
- Inspect the certification path. For me, there is our corporate CA and our SSL Inspection certificate.
- Download each certificate as Base64 encoded into a .cer or .crt file.
- Compile all the certificates as-is into one .cer or .crt file.
- Place this file into a user folder. Though we have a network-based users folder I recommend and use a local machine based folder. Note the full path to this file.
- From a command console, run the following:
npm config set cafile "C:\Local\Path\To\cafile4npm.cer"
modifying the path and file noted in step 8.
- Run your
npm install
command.
回答6:
Did you also tried settings cafile
accommodating all pems in one file? npm add root CA
If you use proxy in your .npmrc
file, I will suggest to set no_proxy
environment variable with value of your <server IP address>
回答7:
In my case, I had installed Fiddler, which has a self signed certificate which made the npm install go crazy.
See here how to remove the self signed Fiddler certificate How do you remove the root CA certificate that Fiddler installs
回答8:
In CentOS and other Linux distros you need to configure NPM to use your Certificate Authorities file:
npm config set cafile "/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem" -g
Obviously check the file exists and contains all CA Roots you may encounter (e.g. corporate proxy).
回答9:
As of February 27, 2014, npm no longer supports its self-signed certificates. The following options, as recommended by npm, is to do one of the following:
Upgrade your version of npm
npm install npm -g --ca=""
-- OR --
Tell your current version of npm to use known registrars
npm config set ca ""
Update: npm has posted More help with SELF_SIGNED_CERT_IN_CHAIN and npm with more solutions particular to different environments
Read more here