梦想吧

1174 分类: WEB前端

Electron打包配置与Electron报错问题解决

打包配置

安装打包工具electron-packager

npm install electron-packager -g

配置打包命令

  "scripts": {
      "pack": "electron-packager ./ '应用名称' --win --out ../myClient --arch=x64 --app-version=0.0.1 --overwrite --ignore=node_modules --asar"
  },

“--ginore” 忽略node_modules目录,防止打包进去,速度慢,而且文件大
“--win” 表示仅打包Windows平台
“--out ../myClient” 表示打包输出目录
更多内容请上api文档查询https://github.com/electron/electron-packager/blob/master/docs/api.md

打包命令

配置好打包命令后在根目录执行npm run pack即可打包,打包成功找到输出目录即可找到exe运行程序

报错问题解决

报错如下

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
at getElectronPath (G:\Project\electron-project\practice\[email protected]@electron\index.js:14:11)
at Object. (G:\Project\electron-project\practice\[email protected]@electron\index.js:18:18)
at Module._compile (module.js:653:30)
at Object.Module._extensions…js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object. (G:\Project\electron-project\practice\[email protected]@electron\cli.js:3:16)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: electron .
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

网上大多说删除重新安装,我试过多个方法无效,升级node至最高等级也无效,后将Electron版本从当前最新版V7.1.1退至V6.1.4,重新安装解决问题。

#JS, JavaScript, Electron

作者: Jim

版权: 除特别声明,均采用BY-NC-SA 4.0许可协议,转载请表明出处

目录Content

评论