yarn add electron 安装失败

yarn add electron 安装失败
今天遇到了yarn
安装包失败的问题,记录下来
之前曾经试过electron
的初步使用,不过已经过去挺长一段时间了。当时自己也写了一篇文章《Electron试水篇(一)》
然后今天想重新试试,对项目进行安装,发现出错了
安装命令:
yarn add --dev electron
然后安装失败:

准备找找之前写的文章,看看当初有没有解决,结果就发现当初自己也没解决啊😭,是用来 npm 下载掉的...... (标准的逃避可耻但有用
)

解决过程
这次不能再姑息了,一定要用yarn
安装成功。
electron
官网上其实也有过安装失败的一些推测,可能是由于网络原因导致的。但是没有具体解决方案

重新下载一下看看问题所在,发现其实卡在了最后一步上, 并且报错中出现了这样一句:
RequestError: connect ETIMEDOUT 20.205.243.166:443

然后去网上查找资料,参考文章:《Electron 项目搭建采坑 RequestError: connect ETIMEDOUT 20.205.243.166:443》
原因
其实由于Electron
是复合型的依赖包,electron
安装要 github 中下载一些脚本,这些文件都在国外的网站,如果对 github 访问网速过低,会导致安装失败。
可以在cmd
中ping github.com
,会发现出现了请求超时

这时,可以去修改C:\Windows\System32\drivers\etc
文件夹下hosts
文件,调整 github。这时发现我 etc 文件夹下并没有hosts

可以在cmd
中使用命令语句创建:
for /f %P in ('dir %windir%\WinSxS\hosts /b /s') do copy %P %windir%\System32\drivers\etc & echo %P & Notepad %P

使用http://ping.chinaz.com/github.com这个网站,对 github 进行 ping 检索。


找到速度较快的,复制 ip。在 hosts 中添加ip地址 github.com
,以管理员身份保存

现在ping github.com
就不会超时了

然后重新输入yarn add electron
,就能看到安装已经成功

在配置安装的过程中,必定会遇到各种各样的问题,即使已经解决过,但是过一段时间就可能会忘记,特别当你查找很久资料才解决的问题,如果不记录,重新遇到时可能极度烦躁。
所以养成记笔记的习惯,本次的问题虽然不是特别难解决,但也记下来吧。
版权声明: 本文为 InfoQ 作者【空城机】的原创文章。
原文链接:【http://xie.infoq.cn/article/38df5d25f3038db554e209372】。
本文遵守【CC-BY 4.0】协议,转载请保留原文出处及本版权声明。
评论