nodejs“npm ERR!代码SELF_SIGNED_CERT_IN_CHAIN”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29141153/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 18:33:07  来源:igfitidea点击:

nodejs "npm ERR! code SELF_SIGNED_CERT_IN_CHAIN"

node.jsnpm

提问by developer82

I'm new to nodejs and npm. I'm trying to install log4js and this is the command for the install:

我是 nodejs 和 npm 的新手。我正在尝试安装 log4js,这是安装命令:

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:

我正在从 Windows 命令行运行它,经过一段时间的标记旋转后,我收到以下错误:

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-morebut I'm still getting this error.

我尝试按照npm config set ca=""此处的建议进行操作:http: //blog.npmjs.org/post/78085451721/npms-self-signed-certificate-is-no-more但我仍然收到此错误。

How can I solve this and install NPMs ?

我该如何解决这个问题并安装 NPM?

回答by Akshay Vijay Jain

As per npm blogLTS is not affected by this issue, so prefer using Latest release

In older versions, npm would have a self signed ca file, a ca file is used in secure SSL mode while making connection, and npm registry deployed updated SSL certificate which is incompatible with ca file of older npm, so the connection error owing to SSL

However if you face this error any ONE of below stepsshould help you
1) upgrade your version of npm

根据 npm blogLTS 不受此问题的影响,因此更喜欢使用最新版本

在旧版本中,npm 将有一个自签名 ca 文件,在建立连接时在安全 SSL 模式下使用 ca 文件,并且 npm 注册表部署了更新的 SSL 证书这与旧 npm 的 ca 文件不兼容,因此由于 SSL 导致连接错误

但是,如果您遇到此错误,以下任何一个步骤都可以帮助您
1) 升级您的 npm 版本

npm install npm -g --ca=null

2) tell your current version of npm to use node's ca instead of built in npm's ca

npm config set ca=""


3) you can also disable strict-ssl mode to get around the error in old version, but you are wiping the security

npm set strict-ssl false

npm install npm -g --ca=null

2) 告诉您当前版本的 npm 使用 node 的 ca 而不是内置的 npm 的 ca

npm config set ca=""


3) 您还可以禁用严格 ssl 模式来解决旧版本中的错误,但您正在清除安全性

npm set strict-ssl false

回答by Ronaldo Moreira

I had the same problem on windows 10.

我在 Windows 10 上遇到了同样的问题。

open windows powerShell and enter the following command:

打开windows PowerShell并输入以下命令:

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

Then you can use:

然后你可以使用:

npm install [your package]

回答by izmaxx

I'm new to npm as well. Besides the commands mentioned in your link I tried the following and it resolved my issues:

我也是 npm 的新手。除了您的链接中提到的命令之外,我还尝试了以下操作并解决了我的问题:

  • npm set strict-ssl false
  • disabled McAfee temporarily
  • npm set strict-ssl false
  • 暂时禁用迈克菲

Reference: Npm SELF_SIGNED_CERT_IN_CHAIN on Azure

参考:Azure 上的 Npm SELF_SIGNED_CERT_IN_CHAIN

回答by Liby George

As metioned by Akshay Vijay Jain above,

正如上面 Akshay Vijay Jain 所提到的,

npm config set strict-ssl false

npm 配置设置严格的 SSL 假

TURNING OFF SSL BEFORE INSTALLING THE LATEST VERSION

在安装最新版本之前关闭 SSL

Then install the latest version

然后安装最新版本

npm install -g npm@latest

npm install -g npm@latest

INSTALL SUCCESS!!

安装成功!!

See the screenshots added for clarity.

为清楚起见,请参阅添加的屏幕截图。

回答by gregsonian

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.

虽然将 StrictSsl 设置为 false 是一种选择,但它会损害您的 npm 安全性。我建议不要禁用它。以下说明详细说明了 Shreedhar 使用 cafile 的帖子。尽管它是从 Windows 10 机器的角度编写的,但它可以进行调整。

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.

我们公司通过代理使用 SSL Inpsection,所以至少我们需要包含 SSL 检查证书。以下说明假设您能够在尝试使用外部访问 npm 功能的机器上使用现代 Web 浏览器。

  1. From a command console, run the following: npm config list
  2. Record the value for metrics-registry. This should be a URL.
  3. Open a browser to the URL. As of writing this answer, it is https://registry.npmjs.org/
  4. 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.
  5. Inspect the certification path. For me, there is our corporate CA and our SSL Inspection certificate.
  6. Download each certificate as Base64 encoded into a .cer or .crt file.
  7. Compile all the certificates as-is into one .cer or .crt file.
  8. 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.
  9. 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.
  10. Run your npm installcommand.
  1. 从命令控制台,运行以下命令: npm config list
  2. 记录 metrics-registry 的值。这应该是一个 URL。
  3. 打开浏览器访问 URL。在撰写此答案时,它是https://registry.npmjs.org/
  4. 打开站点的证书信息。对于 Windows 上的 Chrome,这涉及单击地址栏中 URL 左侧的挂锁图标并选择选项Certificate
  5. 检查认证路径。对我来说,有我们的公司 CA 和我们的 SSL 检查证书。
  6. 将每个证书下载为 Base64 编码到 .cer 或 .crt 文件中。
  7. 将所有证书按原样编译到一个 .cer 或 .crt 文件中。
  8. 将此文件放入用户文件夹中。虽然我们有一个基于网络的用户文件夹,但我推荐并使用基于本地机器的文件夹。请注意此文件的完整路径。
  9. 从命令控制台,运行以下命令:npm config set cafile "C:\Local\Path\To\cafile4npm.cer"修改步骤 8 中记录的路径和文件。
  10. 运行你的npm install命令。

回答by gregsonian

Did you also tried settings cafileaccommodating all pems in one file? npm add root CA

您是否还尝试过cafile在一个文件中容纳所有 pem 的设置?npm 添加根 CA

If you use proxy in your .npmrcfile, I will suggest to set no_proxyenvironment variable with value of your <server IP address>

如果您在.npmrc文件中使用代理,我会建议no_proxy使用您的值设置环境变量<server IP address>

回答by Stefan Cronert

In my case, I had installed Fiddler, which has a self signed certificate which made the npm install go crazy.

就我而言,我安装了 Fiddler,它有一个自签名证书,这让 npm install 变得疯狂。

See here how to remove the self signed Fiddler certificate How do you remove the root CA certificate that Fiddler installs

请参阅此处如何删除自签名 Fiddler 证书如何删除 Fiddler 安装的根 CA 证书

回答by Marc

In CentOS and other Linux distros you need to configure NPM to use your Certificate Authorities file:

在 CentOS 和其他 Linux 发行版中,您需要配置 NPM 以使用您的证书颁发机构文件:

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

显然,检查文件是否存在并包含您可能遇到的所有 CA 根(例如公司代理)。

回答by manish kumar

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:

截至 2014 年 2 月 27 日,npm 不再支持其自签名证书npm 推荐的以下选项是执行以下操作之一:

Upgrade your version of npm

升级你的 npm 版本

npm install npm -g --ca=""

-- OR --

- 或者 -

Tell your current version of npm to use known registrars

告诉您当前版本的 npm 使用已知的注册商

npm config set ca ""

Update:npm has posted More help with SELF_SIGNED_CERT_IN_CHAIN and npmwith more solutions particular to different environments

更新:npm 发布了更多关于 SELF_SIGNED_CERT_IN_CHAIN 和 npm 的帮助,提供了更多针对不同环境的解决方案

Read more here

在这里阅读更多