Electron 渲染进程中报错require is not d

2021-08-27  本文已影响0人  sweetylulu
image.png

解决方法在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
    }
})
上一篇 下一篇

猜你喜欢

热点阅读