版本
vue 3 @3.0.0
electron @ 6.1.12
builder-util @22.10.5
问题1.运行打包命令-》Error: Cannot find module ‘fs/promises’
原因:node 版本不是最新,electron-builder中引用fs方式与老版本node的不一样。require(‘fs/promise’);node旧-require(‘fs’).promise
+DLL-------ffi-napi
问题2:
Uncaught Error: Dynamic Linking Error: Win32 error 126 at new DynamicLibrary
原因:引入dll文件路径不对
问题3:electron运行时报错 Uncaught ReferenceError: require is not defined; || Error: Module did not self-register.
//在new BrowserWindow 创建窗口方法中添加 nodeIntegration:true,
webPreferences: {
contextIsolation: false,
nodeIntegration: true,
}
//在vue.config.js中设置
module.exports = defineConfig({
pluginOptions:{
electronBuilder:{
nodeIntegration:true,
},
},
})
问题5:Uncaught Error: No native build was found for platform=win32 arch=x64 runtime=electron abi=73 uv=1 libc=glibc node=12.4.0 electron=6.1.12 webpack=true
原因:在编译时排除ffi-napi,ref-napi两个依赖,这两个依赖包含c/c++代码,只在运行时启用.
解决:
module.exports = defineConfig({
pluginOptions:{
electronBuilder:{
externals:[
'ffi-napi',
'ref-napi'
],
},
},
})
问题6:Uncaught TypeError: os.arch is not a function
//在vue.config.js中设置
module.exports = defineConfig({
pluginOptions:{
electronBuilder:{
nodeIntegration:true,
},
},
})
问题7:npm run serve 运行时----$ BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.This is no longer the case. Verify if you need this module and configure a polyfill for it.
//在vue.config.js中设置
module.exports = defineConfig({
configureWebpack:()=>{
return {
resolve:{
fallback:{
"path": false,
"os":false,
"fs": false, }},} }
})
问题8: npm run serve 运行时 --Uncaught ReferenceError: require is not defined
Uncaught Error: No native build was found for platform=win32 arch=x64 runtime=electron abi=73 uv=1 libc=glibc node=12.4.0 electron=6.1.12 webpack=true
loaded from: F:\arui\server\ecg-app\node_modules\electron\dist\resources\electron.asar