我在一家公司代理公司工作。我的npm配置如下:
$ npm config get
...
https_proxy = "http://proxy.my-domain.com:8080"
https-proxy = "http://proxy.my-domain.com:8080"
proxy = "http://proxy.my-domain.com:8080"
...
有了这些设置,我可以很好地安装一些软件包,但不能安装其他软件包。例如,$ npm i react
工作得非常好,而安装@babel/core
会抛出一个ECONNRESET错误。
$ npm i @babel/core
npm ERR! code ECONNRESET
npm ERR! syscall read
npm ERR! errno -54
npm ERR! network read ECONNRESET
...
奇怪的是,我能够用纱线来安装这个包(它以npm的方式为代理配置),但是它也告诉我我有网络问题(即使它成功地安装了这个包)。
$ yarn add @babel/core
...
✨ Done in 2.99s.
info There appears to be trouble with your network connection. Retrying...
info There appears to be trouble with your network connection. Retrying...
info There appears to be trouble with your network connection. Retrying...
我不知道为什么它适用于纱线,但不适用于npm。npm调试日志如下所示:
73 silly tarball no local data for @jridgewell/sourcemap-codec@https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz. Extracting by manifest.
74 silly tarball no local data for @jridgewell/trace-mapping@https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.17.tgz. Extracting by manifest.
75 silly tarball no local data for @jridgewell/set-array@https://registry.npmjs.org/@jridgewell/set-array/-/set-array-1.1.2.tgz. Extracting by manifest.
76 verbose stack Error: read ECONNRESET
76 verbose stack at TLSWrap.onStreamRead (node:internal/stream_base_commons:217:20)
77 verbose cwd /Users/justinsmith/Dev/test-npm
78 verbose Darwin 21.4.0
79 verbose node v18.9.0
80 verbose npm v8.19.1
81 error code ECONNRESET
82 error syscall read
83 error errno -54
有人知道为什么会这样吗?
发布于 2022-11-04 10:21:11
tl;dr将此添加到我的~./npmrc中提供了一个临时修复:
# This is what I already had set
proxy=http://proxy.my-domain.com:8080/
https-proxy=http://proxy.my-domain.com:8080/
https_proxy=http://proxy.my-domain.com:8080/
# This is what I added
strict-ssl=false
registry=http://registry.npmjs.org/
maxsockets=3
这迫使npm使用http而不是https发出请求,并将并行请求的数量限制在3个。
这起作用的一个原因是,很明显,公司代理在将文件转发给客户之前,正在扫描文件中的恶意软件。显然,npm在TLS上并行地提出了太多的请求,压倒了恶意软件扫描器,最终拒绝了一些连接。
另一方面,纱线将重试几次,而npm只是抛出一个错误和放弃。
一个长期的解决方案是让您的IT部门将npm添加到恶意软件扫描排除列表中。
完全归功于这个博客帖子,它提供了这些有用的解决方案。
https://stackoverflow.com/questions/74302323
复制相似问题