再Electron 5.0之后,如果需要在渲染進程中使用Node.js的模塊,需要手動將創建窗口時候的nodeIntegration這一選項開啟,這樣就能避免報錯了。
mainWindow = new BrowserWindow({
webPreferences: {
nodeIntegration: true
}
})
// nodeIntegration: true 加上這一句 就可以了 5.0以后默認是false
作者:艾孜爾江