1. 問(wèn)題
今天在安裝 bmap-draw
的時(shí)候發(fā)現(xiàn)安裝失敗了验游,報(bào)錯(cuò)信息如下:
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
查了一下,應(yīng)該是因?yàn)橛?jì)算機(jī)無(wú)法連接到 npm registry
- 首先佩脊,我通過(guò)以下命令排除了代理設(shè)置錯(cuò)誤的情況,返回的都是null,說(shuō)明我沒(méi)有設(shè)置代理:
# 獲取npm的代理設(shè)置
$ npm config get proxy
# 獲取npm的HTTPS代理設(shè)置
$ npm config get https-proxy
- 然后麸拄,通過(guò)以下命令:
# 查看npm的所有配置信息
$ npm config list
得知我原來(lái)設(shè)置的registry
為npm的默認(rèn)模塊倉(cāng)庫(kù)地址https://registry.npmjs.org/
惜索,應(yīng)該是因?yàn)榫W(wǎng)絡(luò)原因特笋,導(dǎo)致無(wú)法連接上,這個(gè)設(shè)置在C:\Users\{username}\.npmrc
文件中巾兆,可以直接修改猎物,也可以通過(guò)npm config set registry {url}
命令進(jìn)行配置虎囚。
2.解決方法
將npm的registry更換為國(guó)內(nèi)源,如淘寶鏡像:
$ npm config set registry https://registry.npm.taobao.org
更換后就安裝成功了蔫磨!