Electron 的 preload.js 里调用 nodejs 的 require 时报错:preload.js:10 Uncaught ReferenceError: global is not defined
只需追加 nodeIntegration: true 和 contextIsolation: false 即可。
const win = new BrowserWindow({
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
preload: path.join(__dirname, 'preload.js')
}
})