代理后面的npm失败,状态为403 [英] npm behind a proxy fails with status 403
问题描述
我正在尝试在代理后面运行 npm 。我已尝试直接或通过 Authoxy 输入代理:
I'm trying to run npm behind a proxy. I've tried both entering the proxy directly or through Authoxy:
npm config set proxy http://localhost:8999
npm config set https-proxy http://localhost:8999
无论我使用哪种代理,运行 npm搜索
时总是会出现同样的错误:
Regardless of which proxy I use, I always end up with the same error when running npm search
:
npm info it worked if it ends with ok
npm verb cli [ 'node', '/usr/local/bin/npm', 'search' ]
npm info using npm@1.1.45
npm info using node@v0.8.4
npm verb config file /Users/xxx/.npmrc
npm verb config file /usr/local/etc/npmrc
npm verb config file /usr/local/lib/node_modules/npm/npmrc
npm WARN Building the local index for the first time, please be patient
npm verb url raw /-/all
npm verb url resolving [ 'https://registry.npmjs.org/', './-/all' ]
npm verb url resolved https://registry.npmjs.org/-/all
npm info retry registry request attempt 1 at 09:48:47
npm http GET https://registry.npmjs.org/-/all
npm info retry will retry, error on last attempt: Error: tunneling socket could not be established, sutatusCode=403
npm info retry registry request attempt 2 at 09:48:57
npm http GET https://registry.npmjs.org/-/all
npm info retry will retry, error on last attempt: Error: tunneling socket could not be established, sutatusCode=403
npm info retry registry request attempt 3 at 09:49:57
npm http GET https://registry.npmjs.org/-/all
npm ERR! Error: tunneling socket could not be established, sutatusCode=403
npm ERR! at ClientRequest.onConnect (/usr/local/lib/node_modules/npm/node_modules/request/tunnel.js:148:19)
npm ERR! at ClientRequest.g (events.js:185:14)
npm ERR! at ClientRequest.EventEmitter.emit (events.js:115:20)
npm ERR! at Socket.socketOnData (http.js:1383:11)
npm ERR! at TCP.onread (net.js:410:27)
该命令始终以<$ c失败$ c> sutatusCode [sic!] 403 - 这意味着未经授权。我已将Authoxy设置为不需要用户名/密码。当我绕过Authoxy并以http:// user:pass @ proxy:port的形式为我们的NTLM代理提供真正的代理凭证时,会发生同样的错误。
The command always fails with sutatusCode
[sic!] 403 - which means unauthorized. I have set up Authoxy to not require a username/password. The same error happens when I bypass Authoxy and provide the real proxy credentials for our NTLM proxy in the form of http:// user:pass@proxy:port.
如何我可以通过代理服务吗?
How can I make this work through the proxy?
更新
我创建了NPM项目报告此问题: https://github.com/isaacs/npm/issues / 2866
I have created an issue on the NPM project to report this: https://github.com/isaacs/npm/issues/2866
推荐答案
好的,所以在发布问题后的几分钟内,我在这里找到答案:
https://github.com/isaacs/npm/issues/2119#issuecomment-5321857
OK, so within minutes after posting the question, I found the answer myself here: https://github.com/isaacs/npm/issues/2119#issuecomment-5321857
问题似乎是npm在代理服务器上使用HTTPS并不是那么好。将注册表URL从HTTPS更改为HTTP为我修复了它:
The issue seems to be that npm is not that great with HTTPS over a proxy. Changing the registry URL from HTTPS to HTTP fixed it for me:
npm config set registry http://registry.npmjs.org/
我仍然需要提供代理配置(在我的情况下通过Authoxy),但一切正常现在。
I still have to provide the proxy config (through Authoxy in my case), but everything works fine now.
似乎是一个常见问题,但没有详细记录。我希望这里的答案能让人们更容易找到他们是否遇到这个问题。
Seems to be a common issue, but not well documented. I hope this answer here will make it easier for people to find if they run into this issue.
这篇关于代理后面的npm失败,状态为403的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!