Electron 12 is now defaulting contextIsolation
to true
, which disables Node (here are the release notes; and here’s the PR).
Here’s a discussion of this change. nodeIntegration
for what it’s worth is going to be removed in a future Electron version.
The easiest way to fix this is to simply disable context isolation:
mainWindow = new BrowserWindow({
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
});
That being said, you might want to consider keeping contextIsolation
enabled for security reasons. See this document explaining why this feature bolsters the security of your application.