0

The renderer process still throws an error

Uncaught ReferenceError: require is not defined
    at <anonymous>:1:1

even though the main process' webPreferences.nodeIntegration was already set to true like so:

function launchMainWindow () {

  const mainWindow = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: true
    }
  })

  mainWindow.loadFile('main.html')
}

This is contradictory to an answer from a similar question. Did I miss something?

What makes the require() method on the renderer process to be undefined?

Warning

Abel Callejo
  • 13,779
  • 10
  • 69
  • 84

1 Answers1

2

You must be using the latest Electron version to this date.

In the newest versions of Electron you need to specify both:

webPreferences: {
    nodeIntegration: true,
    contextIsolation: false
}

You should add this to all your created Windows to allow the usage of require.

Source: ElectronJS

Fuczi Fuczi
  • 415
  • 1
  • 5
  • 13