这次发布项目自动化打包,cnpm install 报错,报错如下:
Get /binary-mirror-config/latest from https://registry.npm.taobao.org error:
ConnectionTimeoutError: Connect timeout for 5000ms, GET
https://registry.npmjs.com/binary-mirror-config/latest -2 (connected: false,
keepalive socket: false, agent status:
{"createSocketCount":4,"createSocketErrorCount":0,"closeSocketCount":4,"errorSocketCount":0,"timeoutSocketCount":0,"requestCount":0,"freeSockets":{},"sockets":{},"requests":{}},
socketHandledRequests: 1, socketHandledResponses: 0) ……
然后使用:time curl -v
https://registry.npm.taobao.org/binary-mirror-config/latest测试,发现时间为6s多,所以一直想办法解决timrout时间的问题,然后一直踩坑,直到幡然醒悟。
踩坑
(1)修改cnpm配置:
cnpm config list -l cnpm config set fetch-retry-mintimeout 10000 cnpm config
set fetch-retry-maxtimeout 20000
无效。
(2)新增配置
cnpm set timeout 10000 cnpm config set timeout 10000
无效。
(3)重新换源
npm config set registry https://registry.npm.taobao.org --global npm install
-g cnpm --registry=https://registry.npm.taobao.org
无效……
2. 重新定位错误
再次查看报错信息,找到报错的根源:
at Timeout._onTimeout
(/nodejs/lib/node_modules/cnpm/node_modules/urllib/lib/urllib.js:849:15) at
ontimeout (timers.js:498:11) at tryOnTimeout (timers.js:323:5) at
Timer.listOnTimeout (timers.js:290:5)
然后找到报错根源:/nodejs/lib/node_modules/cnpm/node_modules/urllib/lib/urllib.js
修改掉文件里面的常量 TIMEOUT、TIMEOUTS 的 5s 为 10s
然后&……
大功告成 !
热门工具 换一换