node.js SSL 错误:使用 npm 命令时 CERT_UNTRUSTED

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21855035/
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 16:52:07  来源:igfitidea点击:

SSL Error: CERT_UNTRUSTED while using npm command

node.jsssl

提问by Sudip7

I am trying to install express framework using npm command but getting following error.

我正在尝试使用 npm 命令安装 express 框架,但出现以下错误。

error message is

错误信息是

E:\myFindings\nodejs_programs\node>npm install -g express
npm http GET https://registry.npmjs.org/express
npm ERR! Error: SSL Error: CERT_UNTRUSTED
npm ERR!     at ClientRequest.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\request\main.js:409:26)
npm ERR!     at ClientRequest.g (events.js:185:14)
npm ERR!     at ClientRequest.EventEmitter.emit (events.js:88:17)
npm ERR!     at HTTPParser.parserOnIncomingClient [as onIncoming] (http.js:1445:7)
npm ERR!     at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:111:23)
npm ERR!     at CleartextStream.socketOnData [as ondata] (http.js:1356:20)
npm ERR!     at CleartextStream.CryptoStream._push (tls.js:396:27)
npm ERR!     at SecurePair.cycle (tls.js:751:20)
npm ERR!     at EncryptedStream.CryptoStream.write (tls.js:131:13)
npm ERR!     at Socket.ondata (stream.js:38:26)
npm ERR!  [Error: SSL Error: CERT_UNTRUSTED]
npm ERR! You may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <[email protected]>

npm ERR! System Windows_NT 6.1.7601
npm ERR! command "C:\Program Files\nodejs\\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "install" "-g" "express"
npm ERR! cwd E:\myFindings\nodejs_programs\node
npm ERR! node -v v0.8.0
npm ERR! npm -v 1.1.32
npm ERR! message SSL Error: CERT_UNTRUSTED
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     E:\myFindings\nodejs_programs\node\npm-debug.log
npm ERR! not ok code 0

help me to sort out

帮我整理一下

采纳答案by Sudip7

I think I got the reason for the above error. It is the corporate proxy(virtual private network) provided in order to work in the client network. Without that connection I frequently faced the same problem be it maven build or npm install.

我想我得到了上述错误的原因。它是为了在客户端网络中工作而提供的公司代理(虚拟专用网络)。没有那个连接,我经常遇到同样的问题,无论是 maven build 还是 npm install。

回答by ramesh.mimit

You can bypass https using below commands:

您可以使用以下命令绕过 https:

npm config set strict-ssl false

or set the registry URL from https or http like below:

或从 https 或 http 设置注册表 URL,如下所示:

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

However, Personally I believe bypassing https is not the real solution, but we can use it as a workaround.

但是,我个人认为绕过 https 不是真正的解决方案,但我们可以将其用作解决方法。

回答by alex

npm ERR! node -v v0.8.0
npm ERR! npm -v 1.1.32

Update your node.js installation.The following commands should do it (from here):

更新您的 node.js 安装。以下命令应该执行此操作(来自此处):

sudo npm cache clean -f
sudo npm install -g n
sudo n stable


Edit: okay, if you reallyhave a good reason to run an ancient version of the software, npm set ca nullwill fix the issue. It happened, because built-in npm certificate has expired over the years.

编辑:好的,如果您真的有充分的理由运行该软件的旧版本,npm set ca null将解决该问题。它发生了,因为内置的 npm 证书多年来已经过期。

回答by majran

I had same problem and finally I understood that my node version is old. For example, you can install the current active LTS node version in Ubuntu by the following steps:

我遇到了同样的问题,最后我明白我的节点版本是旧的。例如,您可以通过以下步骤在 Ubuntu 中安装当前活动的 LTS 节点版本:

sudo apt-get update
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install nodejs -y

Installation instructions for more versions and systems can be found in the following link:

更多版本和系统的安装说明可以在以下链接中找到:

https://github.com/nodesource/distributions/blob/master/README.md

https://github.com/nodesource/distributions/blob/master/README.md

回答by Michael Oakley

If you're behind a corporate proxy, try this setting for npm with your company's proxy:

如果您使用公司代理,请尝试使用您公司的代理为 npm 设置此设置:

npm --https-proxy=http://proxy.company.com install express -g

回答by HerrWalter

Since i stumbled on the post via google:

由于我通过谷歌偶然发现了这篇文章:

Try using npm ciit will be much than an npm install.

尝试使用npm ci它会比npm install.

From the manual:

从手册:

In short, the main differences between using npm install and npm ci are:

  • The project must have an existing package-lock.json or npm-shrinkwrap.json.
  • If dependencies in the package lock do not match those in package.json, npm ci will exit with an error, instead of updating the package lock.
  • npm ci can only install entire projects at a time: individual dependencies cannot be added with this command.
  • If a node_modules is already present, it will be automatically removed before npm ci begins its install.
  • It will never write to package.json or any of the package-locks: installs are essentially frozen.

简而言之,使用 npm install 和 npm ci 的主要区别是:

  • 该项目必须具有现有的 package-lock.json 或 npm-shrinkwrap.json。
  • 如果包锁中的依赖项与 package.json 中的依赖项不匹配,则 npm ci 将退出并显示错误,而不是更新包锁。
  • npm ci 一次只能安装整个项目:无法使用此命令添加单个依赖项。
  • 如果 node_modules 已经存在,它将在 npm ci 开始安装之前自动删除。
  • 它永远不会写入 package.json 或任何包锁:安装基本上是冻结的。

回答by jplattus

Reinstall node, then update npm.

重新安装节点,然后更新 npm。

First I removed node

首先我删除了节点

apt-get purge node

Then install node according to the distibution. Docs here.

然后根据分布安装节点。文档在这里

Then

然后

npm install npm@latest -g