不知道有人碰到没,头大。
系统:unbuntu 24.04 (刚升级的,不知道和这个有没有关系),node/npm 都是 apt 安装的,node 版本 v18.19.1 ,npm 版本 9.2.0 。
npm 无论安装什么包都提示 E407 代理验证错误。
$ npm i typestcript
npm ERR! code E407
npm ERR! 407 Proxy Authentication Required - GET https://registry.npmjs.org/typestcript
我们的确通过配置环境变量使用了代理(内网无法直接连 npm )。这个代理工作是正常的,比如 wget https://registry.npmjs.org/typestcript
都正常下载内容。
npm config set proxy
和npm config set https-proxy
单独设置代理也都试过了。都不行。
1
NessajCN 206 天前 via Android
cat ~/.npmrc
结果 po 一下 另外也发一下你的代理设置 |
2
arfaWong 206 天前
换个国内的源吧
|
3
zhiqiang OP @NessajCN ~/.npmrc 是空的。如果设置 npm config 之后是
``` https-proxy=http://user123:[email protected]:3128/ proxy=http://user123:[email protected]:3128/ ``` 但无论是否设置,都是 E407 错误。环境变量设置了 https_proxy 、all_proxy 、http_proxy ,都指向上面这个代理。 |
4
zhiqiang OP @arfaWong 换国内源一样的错误。我的理解是代理那一层就出错了,还没访问最终目的地。
$ npm config set registry http://mirrors.cloud.tencent.com/npm/ $ npm install typescript npm ERR! code E407 npm ERR! 407 Proxy Authentication Required - GET http://mirrors.cloud.tencent.com/npm/typescript |
5
zhiqiang OP 搜到一个可能有用的信息。我这个代理在其它还没升级到 24.04 的服务器上没问提。看来 24.04 的 ubuntu 或者新版本的 npm 升级了验证体系?
The dreaded NTLM There is an HTTP status code 407 (proxy authentication required), which is the more correct way of saying it's the proxy rather than the destination server that's rejecting your request. That code plagued me for the longest time until after a lot of time on Google, I learned my proxy used NTLM authentication. HTTP basic authentication wasn't enough to satisfy whatever proxy my corporate overlords had installed. I resorted to using Cntlm on my local machine (unauthenticated), then had it handle the NTLM authentication with the upstream proxy. Then I had to tell all the programs that couldn't do NTLM to use my local machine as the proxy - which is generally as simple as setting HTTP_PROXY and HTTPS_PROXY. Otherwise, for npm use (as @Agus suggests): npm config set proxy http://proxy.example.com:3128 npm config set https-proxy http://proxy.example.com:3128 |
6
zhiqiang OP 一个更诡异的是,pnpm 没有问题。只有 npm 有问题。
|
7
NessajCN 206 天前 1
@zhiqiang 试试改成
https-proxy=http://"user123:strategy"@10.24.10.245:3128 proxy=http://"user123:strategy"@10.24.10.245:3128 |
9
zhiqiang OP 不对。我搞错了。还是不行。
|
11
former 205 天前
看错误是 npm 底层在去请求包的时候,走代理 proxy 的 user/pwd 没有设置生效
|