npm ERR! syscall connect npm ERR! errno ETIMEDOUT npm ERR! network request to //registry.npmjs.org/pnpm> failed, reason: connect ETIMEDOUT 104.16.18.35:443 npm ERR! network This is a problem related to network connectivity. npm ERR! network In most cases you are behind a proxy or have bad network settings. npm ERR! network npm ERR! network If you are behind a proxy, please make sure that the npm ERR! network 'proxy' config is set properly. See: 'npm help config' npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/ 2022 -11 -14 T06_57_17_949Z-debug -0.l og

提示连接 registry.npmjs.org 这个地址失败

在网上找到几种方法:

npm config set registry http://registry.npmjs.org/
npm config rm proxy
npm config rm https-proxy

都不生效,并且报错变成了:

npm ERR! code ECONNRESET
npm ERR! network aborted
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly. See: 'npm help config'
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2022-11-14T08_37_45_070Z-debug-0.log

然后测试了一下修改docker网络配置

docker build . -t $CONTAINER_NAME --network=host

正常了一会,但还是超时了:

ERR_PNPM_META_FETCH_FAIL  GET <https://registry.npmjs.org/@nestjs%2Fcommon>: request to <https://registry.npmjs.org/@nestjs%2Fcommon> failed, reason: Socket timeout

最后通过这种方式解决了这个问题:

RUN npm install --omit=dev --registry=https://registry.npm.taobao.org

这个问题不得不说真的很烦,因为每次CI/CD都是卡在这个地方,而且不知道是成功了还是失败了,即使是失败了也要等十几分钟才会抛出异常,每尝试一种解决方案都要等很久,头疼得很,而且最骚的是这个在本地测试没有问题,要上服务器才能知道成功还是失败,让人感觉很痛苦。

分类:
后端
标签: