首页 文章

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

提问于
浏览
232

我在ubuntu上使用npm v1.0.104 / node 0.6.12 - 我在尝试通过npm安装任何新模块时收到下面复制的错误(我之前使用http测试了socket.io,而不是https但是我想知道是否可以导致npm / unsigned certs的问题) . 一旦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

13 回答

  • 3

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

    npm config set strict-ssl false
    

    我不能评论它是否会在此时引起任何其他问题 . 希望能帮助到你 .

  • 30

    As of February 27, 2014, npm no longer supports its self-signed certificates. 按照npm的建议,以下选项是执行以下操作之一:

    Upgrade your version of npm

    npm install npm -g --ca=""
    
    • 要么 -

    Tell your current version of npm to use known registrars

    npm config set ca ""
    

    Update: npm发布了More help with SELF_SIGNED_CERT_IN_CHAIN and npm,其中包含针对不同环境的更多解决方案


    您可能需要也可能不需要在建议中添加 sudo .


    其他选项

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

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

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

    Update npm
    因为你可能在尝试 install 一个包时遇到了这个问题, npm install npm -g 可能会因同样的错误而失败 . 如果是这种情况,请改用 update . 正如Nisanth Sojan所说:

    npm update npm -g
    

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

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

    现在我只是将注册表URL从https切换到http . 像这样:

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

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

  • 294
    npm config set strict-ssl false -g
    

    全局保存

  • 29

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

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

    这可能与以下内容有关:

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

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

    如果您在公司Web代理后面,则应设置正确的 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

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


    另见:npm - Troubleshooting - SSL Error

  • 2

    存储库不再支持自签名证书 . 您需要升级 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 .

    Source: 这最初是对 jnylen 答案的编辑 . 虽然指南说"We welcome all constructive edits, but please make them substantial,"该编辑因"This edit changes too much in the original post; the original meaning or intent of the post would be lost."而被拒绝,我猜社区喜欢单独的答案 .

  • -3

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

    brew uninstall npm
    

    然后

    brew install npm
    

    在osx上为我工作(10.9.1)

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

  • 7

    Quick and clean solution (linux tested) (After fatidic February 27, 2014)


    Uninstall npm

    npm rm npm -g
    

    Install npm (新网址是www.npmjs.org而不是npmjs.org)

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

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

  • 10

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

  • 63

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

  • 8

    在命令之前放置这个似乎工作 NODE_TLS_REJECT_UNAUTHORIZED=0 . 例如: NODE_TLS_REJECT_UNAUTHORIZED=0 npm ...

    最好弄清楚如何使节点看到自签名证书有效 . 上面的严格建议因某些原因对我不起作用 . 如果您了解安全隐患并需要临时快速修复,那么这就是我在Google搜索错误时发现的一些内容 .

  • 209

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

    npm uninstall -g @ angular / cli

    npm缓存清理

    npm install -g @ angular / cli @ latest

相关问题