electron + vue3

版本

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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值