之前在安裝Electron的時(shí)候,經(jīng)常會卡住,這次重新搭建環(huán)境時(shí)又卡住了
$ node install.js
卡在了這一步,半天不動,基本上可以確定,訪問的electron源被墻了,搭梯子也不行,挺惱火的。
在網(wǎng)上搜了搜,找到了解決方案,需要給 electron 明確的指定源。
解決方案如下:
修改~/.npmrc 文件,加入如下代碼:
registry=https://registry.npm.taobao.org
electron_mirror="https://npm.taobao.org/mirrors/electron/"
指定electron的源為淘寶的,再次安裝,果然可以正常安裝了。
網(wǎng)上的原因分析(自己看了一下,確實(shí)是這樣的)
install.js里面的下載是依賴于electron-download這個模塊,這個庫有如下的注釋:
You can set the ELECTRON_MIRROR or NPM_CONFIG_ELECTRON_MIRROR environment variable or mirror opt variable to use a custom base URL for grabbing Electron zips. The same pattern applies to ELECTRON_CUSTOM_DIR and ELECTRON_CUSTOM_FILENAME:
## Electron Mirror of China
ELECTRON_MIRROR="https://npm.taobao.org/mirrors/electron/"
## or for a local mirror
ELECTRON_MIRROR="https://10.1.2.105/"
ELECTRON_CUSTOM_DIR="our/internal/filePath"
You can set ELECTRON_MIRROR in .npmrc as well, using the lowercase name: