再Electron 5.0之后,如果需要在渲染进程中使用Node.js的模块,需要手动将创建窗口时候的nodeIntegration这一选项开启,这样就能避免报错了。

mainWindow = new BrowserWindow({

webPreferences: {
nodeIntegration: true
}
})
// nodeIntegration: true 加上这一句 就可以了 5.0以后默认是false


作者:艾孜尔江