I am making an application with Electron and when I open the developer tools, in the console I get this error:
Uncaught ReferenceError: require is not defined at index.html:11
According to a certain English stackoverflow question , I am supposed to have Node integration enabled in my index.js from which electron bootstrap:
let win = new BrowserWindow({ width: 2200, height: 1200, title: "Contact Remember", maximizable: true, center: true, frame: true, show: true, webPreferences: {
nodeIntegration: true,
enableRemoteModule: true
}});
Which is the attribute nodeIntegration: true
. However this doesn't work for me
According to this other question in English you could use the following resources:
Browserify: Most Node modules can be used in the browser
Webpack: Does everything (packages JavaScript code, CSS, etc.). It was made popular by the rise of React, but is known for its steep learning curve.
Rollup - Take advantage of ES6 modules
I don't want to use any of the above 3 options, because I know that this error will be corrected without using them, because I did it before, although I don't remember how I did it anymore.
Finally, I managed to solve it, by configuring the index.js file with which electron starts:
I have been inspired by this answer from the English stackoverflow site