electron报错:fs.existsSync is not a function

使用vue-cli-plugin-electron-builder创建electron项目,在渲染进程中require('electron')会报错:fs.existsSync is not a function
解决办法:
需要修改两个地方
1.渲染进程中引入模块,改成使用window.require引入

const electron = window.require('electron');

2.主进程中,加上nodeIntegration: true

  win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: true
    }
  })

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: