Reputation: 522
I am creating an application to use mysql. I want to call a function from the main.js file. This main.js file is the main application file, just like the documentation. I saw an example of how to call this function:
const { remote } = require('electron');
const main = remote.require('./main');
main.saveUser();
But it gives the following error:
Uncaught TypeError: Cannot read property 'require' of undefined at app.js:4'
I believe it has updated and the way of calling has changed, can someone help me by sending the link to the documentation that talks about, please.
Upvotes: 2
Views: 1998
Reputation: 522
Solution is very easy. Just add webPreferences: {nodeIntegration: true, enableRemoteModule: true}
in your BrowserWindow in main.js.
The code look like this:
win = new BrowserWindow({
width: 990,
height: 660,
title: "Okkhor52 Tools",
resizable: false,
frame: false,
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true
}
});
Upvotes: 4