const { ipcRenderer } = require(‘electron’)
electron项目中导入ipcRenderer时报错如图所示:
原因:为了安全性,官方将 electron v12.0.0 的 contextIsolation 的默认值改了
解决办法:
在创建窗口方法中添加代码:
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
}
})