0
votes

I am new to electron js and I am trying to use devtron. When I use require in the Electron Browser Window. I face this error

Uncaught ReferenceError: require is not defined

Please note that I am getting this error when using require in BrowserWindow, not in the code. I have also tried setting nodeIntegration: true, and contextIsolation: true in webPreferences. I have attached the screenshot.

enter image description here

Here is my code of main.js

const {app, BrowserWindow} = require('electron')
const path = require('path')
require('electron-reload')(__dirname);



function createWindow () {
  const mainWindow = new BrowserWindow({
    width: 1000,
    height: 700,
    webPreferences: {
      preload: path.join(__dirname, 'preload.js'),
      nodeIntegration: true,
      contextIsolation: true
    }
  })
  mainWindow.loadFile('index.html')
 }

app.whenReady().then(() => {
  createWindow()
  app.on('activate', function () {
    if (BrowserWindow.getAllWindows().length === 0) createWindow()
  })
});
1
Does this answer your question? Unable to use Node.js APIs in renderer process - pushkin

1 Answers

0
votes

contextIsolation is enabled, disable contextIsolation and nodeIntegration should work.

webPreferences: {
  nodeIntegration: true,
  contextIsolation: false
}