electron 安装超时真的很烦,虽然可以自行下载压缩包绕过,但实在不够优雅。
那么如何才能优雅的安装 electron 呢?
要解决先要分析原因;
首先先来看一下报错信息。
> electron@12.0.5 postinstall C:\Users\Sicker\AppData\Roaming\npm\node_modules\electron
> node install.js
RequestError: read ECONNRESET
at ClientRequest.<anonymous> (C:\Users\Sicker\AppData\Roaming\npm\node_modules\electron\node_modules\got\source\request-as-event-emitter.js:178:14)
at Object.onceWrapper (events.js:422:26)
at ClientRequest.emit (events.js:327:22)
at ClientRequest.origin.emit (C:\Users\Sicker\AppData\Roaming\npm\node_modules\electron\node_modules\@szmarczak\http-timer\source\index.js:37:11)
at TLSSocket.socketErrorListener (_http_client.js:469:9)
at TLSSocket.emit (events.js:315:20)
at emitErrorNT (internal/streams/destroy.js:106:8)
at emitErrorCloseNT (internal/streams/destroy.js:74:3)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! electron@12.0.5 postinstall: `node install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the electron@12.0.5 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Sicker\AppData\Roaming\npm-cache\_logs\2021-04-28T05_30_41_032Z-debug.log
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
从日志高亮处,我们可以得出,这是一个连接超时的问题。
链接超时,显而易见。不是因为墙就是连接速度不济所引发。而多次尝试肯定是跟优雅不着边的,那么剩下的自然是解决墙的问题。
被「你怕吗」折腾过的同学肯定要抢答了,「用淘宝镜像呗」
没错,所以下属方法其实也就是围绕解决墙问题而展开罢了。
首先找到 npm
的本地配置路径
npm config ls -l
1
仔细找找,可以找到 .npmrc
相关的条目,打开该路径的文件。
千万别客气,把以下配置通通加进去
ELECTRON_MIRROR=http://npm.taobao.org/mirrors/electron/ CHROMEDRIVER_CDNURL=https://npm.taobao.org/mirrors/chromedriver ELECTRON_BUILDER_BINARIES_MIRROR=https://npm.taobao.org/mirrors/electron-builder-binaries/ registry=https://registry.npm.taobao.org/
什么?你说你没有找到?
那只能麻烦你一条条添加啦
npm config set registry https://registry.npm.taobao.org
npm config set ELECTRON_MIRROR http://npm.taobao.org/mirrors/electron/
npm config set CHROMEDRIVER_CDNURL https://npm.taobao.org/mirrors/chromedriver
npm config set ELECTRON_BUILDER_BINARIES_MIRROR https://npm.taobao.org/mirrors/electron-builder-binaries/
1
2
3
4
2
3
4
最后验证下
npm config get registry
npm config get ELECTRON_MIRROR
npm config get CHROMEDRIVER_CDNURL
npm config get ELECTRON_BUILDER_BINARIES_MIRROR
1
2
3
4
2
3
4
最后安装成功后,运行 electron
。
好了,感谢淘宝吧!
# issues
- 别再用 electron-rebuild 了
否则,安装的版本为 1.4.13 ... 想必你也不想用远古版本的吧?
- 提示安装失败后,再次安装提示 文件已存在
移除 npm -g bin
路径已存在的如上图选中的三个文件后重试