1. 问题
今天在安装 bmap-draw
的时候发现安装失败了,报错信息如下:
npm ERR! code ETIMEDOUT
npm ERR! errno ETIMEDOUT
npm ERR! network request to https://registry.npmjs.org/bmap-draw failed, reason: connect ETIMEDOUT 104.16.1.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! C:\Users\xxx\AppData\Roaming\npm-cache\_logs\2023-12-13T10_10_05_143Z-debug.log
查了一下,应该是因为计算机无法连接到 npm registry
- 首先,我通过以下命令排除了代理设置错误的情况,返回的都是null,说明我没有设置代理:
# 获取npm的代理设置
$ npm config get proxy
# 获取npm的HTTPS代理设置
$ npm config get https-proxy
- 然后,通过以下命令:
# 查看npm的所有配置信息
$ npm config list
得知我原来设置的registry
为npm的默认模块仓库地址https://registry.npmjs.org/
,应该是因为网络原因,导致无法连接上,这个设置在C:\Users\{username}\.npmrc
文件中,可以直接修改,也可以通过npm config set registry {url}
命令进行配置。
2.解决方法
将npm的registry更换为国内源,如淘宝镜像:
$ npm config set registry https://registry.npm.taobao.org
更换后就安装成功了!
网友评论