1:打包时,下载资源超时:
# 使用国内源,参见 安装 或 生成软件 教程
2:打包失败(异常)
错误1:pyton 。。。。。解决:升级构建包,npm install electron-builder@23.0.6
错误2:打包报错Fatal error: Unable to commit changes原因:1. 磁盘是不是满了 ,这个坑也困扰了我半个小时,虽然不长,但是是低级错误2. 杀毒软件,我把电脑管家关了就好了,还有mcfee,麦克非那个杀毒等等。3. 使用makensis包时,账户名为中文,构建异常。解决:1. 清理磁盘2. 退出杀毒软件3. https://www.azimiao.com/6250.html
错误3:...resource\app.asar does not exist ...解决:electron-egg/目录中,如果有app目录,则该目录必须是个普通文件目录,不能为项目目录,比如,app/目录内,不能有 .git、 package.json、node_modules等文件。
错误4:...Need executable 'ar' to convert dir to deb原因:fpm 工具需要 ar 命令才能打包deb, 安装binutils解决:sudo apt install binutils
错误5:...Cannot find module 'fs/promises'原因:electron-builder包版本太高,一些语法不兼容解决:降低electron-builder版本
3:打包后,运行闪退 或 报错
闪退
# 开发模式正常,打包后运行闪退1. 查看日志中是否有报错2. 在cmd中运行程序,可看到打包后的程序运行是否有异常错误(日志中没有的)如:d:/soft/electron-egg.exe 按“回车”
报错1:代码被过滤

该图显示 ./app.asar/electron not exits
原因:未使用加密功能,但是把源码过滤了,导致找不到代码。
处理:请查看 代码加密文档
报错2:bytecode加密时,代码不规范

该图显示 TypeError Class constructor ExampleService cannot be invoked withou ‘new’ at ……
原因:每个加密的class文件,需要添加 toString() 方法
处理:请查看 代码加密文档 中 代码要求
4:cmd控制台乱码
参照:中文乱码
5:npm包缺失或异常
安装异常时,删掉node_modules和package-lock文件
# 1、如:cannot find module 'debug'解决:npm install debug --save# 2、npm install安装异常时删掉 package-lock.json删掉 node_modules文件夹重新执行 npm install 或 cnpm install# 备注包问题,都用npm安装,不要用cnpm、pnpm、yarn
6:白屏、api 404、跨越问题
# dev模式白屏问题1:先启动前端服务,再启动桌面服务,请查看文档中开发步骤# 使用了代理问题2:代理导致api找不到解决方法:1:把代理模式,换成 环境变量模式,如:在.env(开发环境、生产环境)文件里定义多个url变量并赋值,代码中的url地址用环境变量代替。2:设置config.default.json中的windowsOption.webPreferences.webSecurity=true
7:安装 better-sqlite3 失败
# error 1......env: python: No such file or directorymake: *** [Release/sqlite3.a] Error 127rm ba23eeee118cd63e16015df367567cb043fed872.intermediategyp ERR! build errorgyp ERR! stack Error: `make` failed with exit code: 2gyp ERR! stack at ChildProcess.onExit (/Users/apple/.nvm/versions/node/v14.16.0/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)......# 原因需要python环境,(MacOS高版本,不再提供默认python)# 解决方案如Mac系统(其它系统请自己百度Python安装方法)1. brew install python@3.92. vim ~/.zshrc 添加# pythonalias python='/usr/local/bin/python3'export PATH="/usr/local/opt/python@3.9/libexec/bin:$PATH"3. source ~/.zshrc
# error 2......gyp ERR! build errorgyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\14.0\bin\MSBuild.exe` failed with exit code: 1gyp ERR! stack at ChildProcess.onExit (C:\nvm\v14.16.0\node_modules\npm\node_modules\node-gyp\lib\build.js:194:23)gyp ERR! stack at ChildProcess.emit (events.js:315:20)gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)gyp ERR! System Windows_NT 10.0.19041gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\nvm\\v14.16.0\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--release"gyp ERR! cwd D:\www\xing\oschina-desktop\node_modules\better-sqlite3......# 原因需要node-gyp工具# 解决方案执行命令:npm i node-gyp -g
# 错误3......was compiled against a different Node.js version usingNODE_MODULE_VERSION 83. This version of Node.js requiresNODE_MODULE_VERSION 89. Please try re-compiling or re-installing......# 原因sqlite包是用c\c++写的,下载的可执行程序可能与你的操作系统不一致,因此需要根据源代码重新构建。# 解决方案执行命令:npm run re-sqlite
# 错误4......Error: node-gyp failed to reuild ......electron-edge-jsError: ...BuildTools\MSBuild\15.0\Bin\.........# 原因缺少微软构建工具# 解决方案执行命令:npm --vs2015 i -g --production windows-build-tools
8:在浏览器中打开vue启动的服务地址(http://localhost:8080)报错
错误:Uncaught TypeError: window.require is not a function......原因:vue项目中有个demo功能需要访问electron模块,在普通浏览器中是不能解析的。处理:尽量在electron启动的窗口中调试前端页面吧。
9:开发模式时,前端代码在electron-egg渲染界面无法自动更新
点击electron-egg菜单->View->Reload,重新加载。
10:node module版本不匹配
# 错误......was compiled against a different Node.js version usingNODE_MODULE_VERSION 83. This version of Node.js requiresNODE_MODULE_VERSION 89. Please try re-compiling or re-installing......# 原因一些npm包是用c\c++等其它语音写的,下载的可执行程序可能与你的操作系统不一致,因此需要根据源代码重新构建。# 解决方案electron-rebuild -f -w 模块名
11:macOS系统下,自动更新失败
// 尝试关闭asar功能1. 检查确认苹果签名账号2. 修改package.json中,build对象asar属性值为false3. 使用代码加密功能,以防源码暴露
12:软件黑屏或者卡死
错误: ... ERROR:gpu_memory_buffer_support_x11.cc......原因:win7或者Linux系统,不支持gpu加速处理:在main.js文件的ready()方法中关闭硬件加速伪代码:const isWin7 = os.release().startsWith('6.1');const isLinux = true;if (isWin7 || isLinux) {app.disableHardwareAcceleration();}
13:win7操作系统
由于win7不在更新,要想支持的话,请使用下面版本
electron: 11.5.0 (建议 <= 12.x.x)node: v12.18.3 (建议 <= 12.x.x)electron-builder: 22.10.5 (建议 <= 22.10.x)
