导入新项目,执行npm install时卡着不动了,我们使用如下命令来显示更详细的输出信息。
npm install --verbose
通过添加--verbose选项,npm会输出更多的日志信息,包括正在下载的包、安装过程中的各个步骤以及可能出现的错误信息。这个选项通常用于调试和排查安装问题。当你遇到npm包安装失败或者出现其他问题时,使用--verbose可以提供更多的上下文信息,帮助你找到问题所在。
npm warn old lockfile Could not fetch metadata for @antv/coord@0.1.0 FetchError: request to https://registry.npmjs.org/@antv%2fcoord failed, reason: connect ETIMEDOUT 150.242.56.251:443
npm warn old lockfile at ClientRequest.<anonymous> (D:\softFile\Node.js\node_modules\npm\node_modules\minipass-fetch\lib\index.js:130:14)
npm warn old lockfile at ClientRequest.emit (node:events:519:28)
npm warn old lockfile at _destroy (node:_http_client:880:13)
npm warn old lockfile at onSocketNT (node:_http_client:900:5)
npm warn old lockfile at process.processTicksAndRejections (node:internal/process/task_queues:83:21) {
npm warn old lockfile code: 'ETIMEDOUT',
npm warn old lockfile errno: 'ETIMEDOUT',
npm warn old lockfile syscall: 'connect',
npm warn old lockfile address: '150.242.56.251',
npm warn old lockfile port: 443,
npm warn old lockfile type: 'system'
npm warn old lockfile }
**原因:**由于访问国内访问npm的资源库地址(https://registry.npmjs.org)连接超时导致。
解决办法
将npm的镜像源设置为国内的即可(任选一种):
# 更换成淘宝镜像源
npm config set registry https://registry.npmmirror.com/
# 更换成阿里镜像源
npm config set registry https://npm.aliyun.com/
# 更换成华为镜像源
npm config set registry https://mirrors.huaweicloud.com/repository/npm/
# 更换成腾讯镜像源
npm config set registry http://mirrors.cloud.tencent.com/npm/
设置完成后,重新执行npm即可。
**扩展:**通过下面命令可查看当前的镜像源
npm config get registry