
解决方法在new BrowserWindow时添加配置
mainWindow = new BrowserWindow({
webPreferences: {
nodeIntegration: true
}
})
原因: electron 5.0 后 nodeIntegration 默认为 false··
为了安全性,官方将 electron v12.0.0 的 contextIsolation 的默认值改成了true。所以electron v12.0.0以后要在渲染进程里调用 require 的话,还需要加上 contextIsolation: false 。
mainWindow = new BrowserWindow({
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
})
网友评论