electron 导入ipcRenderer报错

const { ipcRenderer } = require(‘electron’)

electron项目中导入ipcRenderer时报错如图所示:
引入ipcRenderer时报错如图
原因:为了安全性,官方将 electron v12.0.0 的 contextIsolation 的默认值改了

解决办法
在创建窗口方法中添加代码:

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

Guess you like

Origin blog.csdn.net/Lc_style/article/details/117125567