当我尝试使用 npm 安装软件包时,它不起作用。经过漫长的等待,我最终得到一个错误'隧道套接字无法建立,sutatusCode = 403'。
$ npm install coffee-script
npm http GET https://registry.npmjs.org/coffee-script
npm http GET https://registry.npmjs.org/coffee-script
npm http GET https://registry.npmjs.org/coffee-script
npm ERR! Error: tunneling socket could not be established, sutatusCode=403
npm ERR! at ClientRequest.onConnect (c:\Program Files\nodejs\node_modules\npm\node_modules\request\tunnel.js:148:19)
npm ERR! at ClientRequest.g (events.js:193:14)
npm ERR! at ClientRequest.EventEmitter.emit (events.js:123:20)
npm ERR! at Socket.socketOnData (http.js:1393:11)
npm ERR! at TCP.onread (net.js:403:27)
但是,当我在我的网络浏览器(谷歌浏览器)中浏览到相同的 URL 时,它加载得很好(见脚注)。https://registry.npmjs.org/coffee-script
怎么了?
虽然我碰巧使用了 https 代理,但我相信这不是问题。我已经配置了环境变量https_proxy
(根据 npm用户指南)。我知道环境变量是正确的,因为 Python 包管理器pip
正确地遵循它。
我相信这个问题与 SSL 证书有关,因为如果我使用 下载该 URL wget
,我会收到关于证书的明确错误
$ wget https://registry.npmjs.org/coffee-script
SYSTEM_WGETRC = c:/progra~1/wget/etc/wgetrc
syswgetrc = c:/progra~1/wget/etc/wgetrc
--2012-12-17 12:14:07-- https://registry.npmjs.org/coffee-script
Resolving corpproxy... 10.254.215.35
Connecting to corpproxy|10.254.215.35|:8080... connected.
ERROR: cannot verify registry.npmjs.org's certificate, issued by `/C=US/ST=CA/L=Oakland/O=npm/OU=npm Certificate Authority/CN=npmCA/emailAddress=i@izs.me':
Unable to locally verify the issuer's authority.
To connect to registry.npmjs.org insecurely, use `--no-check-certificate'.
Unable to establish SSL connection.
我怎样才能解决这个问题?在不影响安全性的情况下。
我曾经在我的网络浏览器中遇到 SSL 证书错误,直到我在控制面板的 Internet 选项中将“npmCA”证书安装为“受信任的根证书颁发机构”(截图)
编辑:我根据https://npmjs.org/doc/config.html#strict-ssl尝试了一个不安全的解决方法
npm set strict-ssl false
然而它仍然超时并出现同样的错误
$ npm install coffee-script
npm http GET https://registry.npmjs.org/coffee-script
npm http GET https://registry.npmjs.org/coffee-script
npm http GET https://registry.npmjs.org/coffee-script
npm ERR! Error: tunneling socket could not be established, sutatusCode=403