使用npm时收到错误:“错误:SSL错误:SELF_SIGNED_CERT_IN_CHAIN”

node.js Node.js

Stafan阿飞

2020-03-19

我在ubuntu上使用npm v1.0.104 / node 0.6.12-我在尝试通过npm安装任何新模块时收到以下复制的错误(我之前使用http而不是https测试了socket.io,但我想知道是否可以导致npm / unsigned证书出现问题)。一旦npm尝试解析“ https://registry.npmjs.org ” URL,该错误就会弹出无论如何,我可以忽略该错误,或​​者定位/将证书添加到受信任的存储中以便继续使用npm。

对于解决该问题需要采取的措施的任何见解将不胜感激(我更愿意通过配置解决问题,而不是尽可能重新安装)。

错误:“错误:SSL错误:SELF_SIGNED_CERT_IN_CHAIN”

完整讯息:

npm ERR! Error: SSL Error: SELF_SIGNED_CERT_IN_CHAIN
npm ERR!     at ClientRequest.<anonymous> (/usr/lib/node_modules/npm/node_modules/request/main.js:252:28)
npm ERR!     at ClientRequest.emit (events.js:67:17)
npm ERR!     at HTTPParser.onIncoming (http.js:1261:11)
npm ERR!     at HTTPParser.onHeadersComplete (http.js:102:31)
npm ERR!     at CleartextStream.ondata (http.js:1150:24)
npm ERR!     at CleartextStream._push (tls.js:375:27)
npm ERR!     at SecurePair.cycle (tls.js:734:20)
npm ERR!     at EncryptedStream.write (tls.js:130:13)
npm ERR!     at Socket.ondata (stream.js:38:26)
npm ERR!     at Socket.emit (events.js:67:17)
npm ERR! Report this *entire* log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <npm-@googlegroups.com>
npm ERR! 
npm ERR! System Linux 2.6.38-13-generic
npm ERR! command "node" "/usr/bin/npm" "install" "jed"
npm ERR! node -v v0.6.12
npm ERR! npm -v 1.0.104

第2286篇《使用npm时收到错误:“错误:SSL错误:SELF_SIGNED_CERT_IN_CHAIN”》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

10个回答
LEYStafan 2020.03.19

关闭SSL似乎是一个非常糟糕的主意。npm的博客解释说,他们不再支持其自签名证书。他们建议通过升级npm npm install npm -g,但我当然也遇到了同样的SELF_SIGNED_CERT_IN_CHAIN错误。因此,我只是更新了节点,它同时更新了npm。确切过程取决于首先安装节点的方式。

神乐西里 2020.03.19

快速干净的解决方案(已通过linux测试)(2014年2月27日生效)


卸载npm

npm rm npm -g

安装npm(新的URL是www.npmjs.org而不是npmjs.org

curl https://www.npmjs.org/install.sh | sh

提示:如何在Linux中安装node.js https://stackoverflow.com/a/22099363/333061

樱路易 2020.03.19

卸载NPM,然后重新安装。

自2014年2月27日起,npm不再支持其自签名证书。 http://blog.npmjs.org/post/78085451721/npms-self-signed-certificate-is-no-more

上面的链接建议使用NPM升级NPM。这也会因SELF_SIGNED_CERT_IN_CHAIN而失败...

GONear 2020.03.19

存储库不再支持自签名证书。您需要升级npm

// Disable the certificate temporarily in order to do the upgrade
npm config set ca ""

// Upgrade npm. -g (global) means you need root permissions; be root 
// or prepend `sudo`
sudo npm install npm -g

// Undo the previous config change
npm config delete ca

// For Ubuntu/Debian-sid/Mint, node package is renamed to nodejs which 
// npm cannot find. Fix this:
sudo ln -s /usr/bin/nodejs /usr/bin/node

您需要打开一个新的终端会话才能使用更新的npm

资料来源:这最初是对jnylen答案的编辑尽管指南中说“我们欢迎所有有建设性的修改,但请对其进行实质性的修改”,但由于“此修改在原始帖子中的更改太大;该帖子的原始含义或意图会丢失” ,因此该编辑被拒绝我想社区更喜欢一个单独的答案。

null 2020.03.19

对于那些在Mac上存在相同问题并通过homebrew安装npm的用户

brew uninstall npm

然后

brew install npm

在osx(10.9.1)上为我工作

编辑:您可能需要brew update安装npm之前。您也可以brew upgrade在更新自制软件后执行brew doctor如果您遇到其他任何问题,也可能会有所帮助

村村凯 2020.03.19

将其放在命令之前似乎可行NODE_TLS_REJECT_UNAUTHORIZED=0例如:NODE_TLS_REJECT_UNAUTHORIZED=0 npm ...

最好弄清楚如何使节点将自签名证书视为有效。出于某些原因,上面的strict-ssl建议对我不起作用。如果您了解安全隐患并且需要临时快速修复,这就是我在Google搜索错误期间的一些随机github问题发现的内容。

Tony小胖 2020.03.19

您需要升级npm。

// Do this first, or the upgrade will fail
npm config set ca ""

npm install npm -g

// Undo the previous config change
npm config delete ca

您可能需要为这些命令加上前缀sudo

来源:http//blog.npmjs.org/post/78085451721/npms-self-signed-certificate-is-no-more

Stafan斯丁 2020.03.19

运行以下命令有助于解决此问题:

npm config set strict-ssl false

我目前无法评论它是否会引起任何其他问题。希望能帮助到你。

西门前端A 2020.03.19
npm config set strict-ssl false -g

全局保存

Stafan西门凯 2020.03.19

现在,我只是将注册表URL从https切换为http。像这样:

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

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android