使用npm时收到错误:'错误:SSL错误:SELF_SIGNED_CERT_IN_CHAIN'

时间:2012-03-09 00:01:24

标签: node.js ssl-certificate npm

我在ubuntu上使用npm v1.0.104 / node 0.6.12 - 我在尝试通过npm安装任何新模块时收到下面复制的错误(我之前使用http测试了socket.io,而不是https虽然& am想知道这是否会导致npm / unsigned certs的问题)。 npm尝试解析“https://registry.npmjs.org”网址时会弹出错误。无论如何我可以忽略错误或者可能找到/添加证书到受信任的商店以继续使用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

15 个答案:

答案 0 :(得分:307)

运行以下内容有助于解决问题:

npm config set strict-ssl false

我无法评论此时是否会引起任何其他问题。希望它有所帮助。

答案 1 :(得分:208)

截至2014年2月27日,npm no longer supports its self-signed certificates以下选项(按照npm的建议)执行以下操作之一:

升级您的npm版本

npm install npm -g --ca=""

- 或 -

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

npm config set ca ""

更新:npm已发布More help with SELF_SIGNED_CERT_IN_CHAIN and npm更多针对不同环境的解决方案


<小时/> 您可能需要也可能不需要在sudo前加上建议。


其他选项

似乎人们在使用npm的建议时遇到问题,所以这里有一些其他潜在的解决方案。

升级节点本身
收到此错误可能表示您有一个较旧版本的节点,该节点自然带有较旧版本的npm。一种解决方案是升级您的Node版本。这可能是最佳选择,因为它可以为您提供最新信息并修复现有的漏洞和漏洞。

此过程取决于您如何安装Node,操作系统等。

更新npm
由于您可能在尝试install包时遇到此问题,npm install npm -g可能会因同一错误而失败。如果是这种情况,请改用update。正如Nisanth Sojan所说:

npm update npm -g

更新npm替代
解决潜在问题的一种方法是使用已知的注册商,安装,然后停止使用已知的注册商。正如jnylen所说:

npm config set ca ""
npm install npm -g
npm config delete ca

答案 2 :(得分:64)

目前我只是将注册表网址从https切换为http。像这样:

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

答案 3 :(得分:32)

npm config set strict-ssl false -g

全球保存

答案 4 :(得分:30)

您需要升级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

答案 5 :(得分:11)

错误SELF_SIGNED_CERT_IN_CHAIN表示您在证书链中拥有自签名证书,该证书基本上不受系统信任。

如果发生这种情况,基本上会发生一些可疑的事情,因此正如人们已经评论过的那样,不建议仅禁用证书检查,但更好的方法是了解问题是什么并解决原因。

这可能与:

有关
  • 自定义存储库地址,但没有正确的证书,

  • 具有透明代理的公司网络。

    如果您在公司网络代理后面,则应设置正确的HTTP_PROXY / HTTPS_PROXY环境变量或通过npm设置它们:

    npm config set proxy http://proxy.company.com:8080
    npm config set https-proxy http://proxy.company.com:8080
    

    请参阅:How to setup Node.js and Npm behind a corporate web proxy

如果您信任主机,则可以从链中导出自签名证书并将其导入系统,以便将其标记为受信任。

这可以通过检查证书(将example.com更改为基于npm-debug.log失败的npm repo)来实现:

openssl s_client -showcerts -connect example.com:443 < /dev/null

然后将证书内容(BEGINEND之间)保存到.crt文件中以便导入。

的Linux

根据suggestion,您可以将导出的证书添加到/etc/environment文件(节点7.4+)中,例如:

NODE_EXTRA_CA_CERTS=/etc/pki/ca-trust/source/anchors/yourCer‌​ts.pem

CentOS的

在CentOS 5上,这可以附加到/etc/pki/tls/certs/ca-bundle.crt文件中,例如

ex +'g/BEGIN CERTIFICATE/,/END CERTIFICATE/p' <(echo | openssl s_client -showcerts -connect example.com:443) -scq | sudo tee -a /etc/pki/tls/certs/ca-bundle.crt
sudo update-ca-trust force-enable
sudo update-ca-trust extract
npm install

注意:要仅导出第一个证书,请在开头删除g

在CentOS 6中,证书文件可以复制到/etc/pki/ca-trust/source/anchors/

的Ubuntu / Debian的

在Ubuntu / Debian中,将CRT文件复制到/usr/local/share/ca-certificates/,然后运行:

sudo update-ca-certificates

MACOS

在macOS中,您可以运行:

sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ~/foo.crt

在Windows中:certutil -addstore -f "ROOT" new-root-certificate.crt

另请参阅:npm - Troubleshooting - SSL Error

答案 6 :(得分:8)

存储库不再支持自签名证书。您需要升级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 的回答的编辑。虽然指南说“我们欢迎所有建设性的修改,但请让它们充实,”由于“此编辑在原始帖子中变化太多,原始含义或意图,编辑被拒绝该帖子将丢失。“我想社区更喜欢单独的答案。

答案 7 :(得分:7)

对于那些在 mac 上遇到相同问题并通过自制安装npm的人:

brew uninstall npm

然后

brew install npm

在osx上为我工作(10.9.1)

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

答案 8 :(得分:3)

快速清洁解决方案(经过linux测试)(2014年2月27日之后)


卸载npm

npm rm npm -g

安装npm (新网址为 www.npmjs.org 而非 npmjs.org

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

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

答案 9 :(得分:3)

仅适用于Windows开发

brushElement.addEventListener('change', (e) => {
  document.documentElement.style.setProperty('--brushcolor', e.target.value);
});

答案 10 :(得分:3)

如果您别无选择,我已经创建了一篇文章,如何在企业防火墙后面禁用大多数 npm 问题。

请注意,您可能容易受到攻击。

https://wnderlvst.com/stories/102a237a-cea1-463b-89db-82224f1c1cbe

Powershell

yarn config set "strict-ssl" false
yarn config set "network-timeout" 600000
$env:NODE_TLS_REJECT_UNAUTHORIZED=0

答案 11 :(得分:2)

卸载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 ......

也会失败

答案 12 :(得分:1)

关闭SSL似乎是一个非常糟糕的主意。 npm's blog解释说他们不再支持他们的自签名证书。他们建议通过npm install npm -g升级npm,但我当然得到了相同的SELF_SIGNED_CERT_IN_CHAIN错误。所以我刚刚更新了节点,它随之更新了npm。确切的过程取决于您首先安装节点的方式。

答案 13 :(得分:1)

在命令看来NODE_TLS_REJECT_UNAUTHORIZED=0之前将其放入。 例如:NODE_TLS_REJECT_UNAUTHORIZED=0 npm ...

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

答案 14 :(得分:-3)

请检查您的互联网连接并确保其正常工作。 确保已安装节点和npm 并在命令提示符下运行以下命令

npm卸载-g @ angular / cli

npm缓存清理

npm install -g @ angular / cli @ latest

相关问题