0

Hi everyone I've got this problem: I'm making a native code editor with electron.js following a tutorial on youtube: https://www.youtube.com/watch?v=SQLSBva6BkQ&list=PLTHrJfrjCyJAxErpBW4B1IXFU3tpn61r6&index=4 In lesson 4 he teaches you how to make a custom frame/titlebar.

in the main page I wrote this: <script src="js/titleBarStuff.js"></script>

in titleBarStuff.js I wrote this:

const remote = require("electron").remote; //I get the error at this line

var minimize = document.getElementById('minimize'); var maximize = document.getElementById('maximize'); var quit = document.getElementById('quit');

minimize.addEventListener("click", minimizeApp); maximize.addEventListener("click", maximizeApp); quit.addEventListener("click", quitApp);

function minimizeApp(){ console.log("app min") remote.BrowserWindow.getFocusedWindow().minimize(); }

function maximizeApp(){ remote.BrowserWindow.getFocusedWindow().maximize(); }

function quitApp(){ remote.BrowserWindow.getCurrentWindow.close(); }

function createWindow(){

win = new BrowserWindow({

widht:900, height:800, minHeight:650, minWidth:600, frame:false,

webPreferences: { nodeIntegration: true } }) }

But I get this error:

Uncaught ReferenceError: require is not defined
at titleBarStuff.js:1

How do I resolve it?

Community
  • 1
  • 1
gioggino
  • 3
  • 7

1 Answers1

0

Add the following object to your main.js file inside the createWindow function.

webPreferences: {
      nodeIntegration: true,
      contextIsolation: false,
      enableRemoteModule: true,-+

}
BestMat
  • 11
  • 4