Electron报错Electron failed to install correctly

xiaohai 2021-09-12 16:38:52 3032人围观 标签: Electron 
简介报错Electron failed to install correctly, please delete node_modules/electron and try installing again处理

参考地址:electron 安装失败,Electron failed to install correctly

整了下electron-egg,结果npm install后始终报错,内容如下:

throw new Error('Electron failed to install correctly, please delete node_modules/electron and try installing again')

Error: Electron failed to install correctly, please delete node_modules/electron and try installing again
....

删了安装,安装了又删除,还是没办法。看到了上面链接的文章,终于解决了。

解决方法

1、删除 node_modules/electron
2、设置系统环境变量(设置 electron 使用淘宝源)

我这里是windows系统
图片alt

ELECTRON_MIRROR=http://npm.taobao.org/mirrors/electron/

最后的/不要忘了。

3、安装Electron
npm install electron
4、修改文件

文件路径:node_modules/@electron/get/dist/cjs/artifact-utils.js
图片alt

const path = details.version.replace(/^v/,'');

这一步主要是处理淘宝源的路径中没有v,如:
原因在于,electron 在 node install.js 里面默认生成的下载的文件路径是这个:

https://npm.taobao.org/mirrors/electron/v8.0.2/electron-v8.0.2-win32-x64.zip

而淘宝源里面的这个资源的路径是这个:

https://npm.taobao.org/mirrors/electron/8.0.2/electron-v8.0.2-win32-x64.zip
# 5、安装

切换到node_modules/electron,执行下面的命令:

node install.js

由于 electron 在 install 之后,是会执行 node install.js 去下载一个平台、版本对应的包,失败的原因就下载这个包,报错了,然后 npm 或者 yarn 在 install 的时候没有任何报错,运行的时候就告诉你上面的错误信息,安装失败了,删了再来永远是不会成功的。

感谢上面的博主,苦苦整了很久,终于解决了。