i am getting the error from a dependency (electron-edge) of an electron/node js app. The node.js version is 5.5.0 and electron version is 0.36.7
To complete Mark Meyer answer : if you're using create-react-app with electron, you cannot modify webpack without ejecting create-react-app. Here is a solution using @craco/craco :
npm i --save @craco/craco
Replace create-react-app by craco in your package.json scripts :
"scripts": {
"start": "craco start",
"build": "craco build",
"test": "craco test",
"electron": "electron ."
},
Add craco.config.js to the root directory
module.exports = {
webpack: {
configure: {
target: 'electron-renderer'
}
}
};
Modify your main.js file:
mainWindow = new BrowserWindow(
{
width: 800,
height: 600,
webPreferences: { // add
nodeIntegration: true // these
} // lines
});
Then from you js file, to open file dialog for example, use window.require :
const remote = window.require('electron').remote;
remote.dialog.showOpenDialog(remote.getCurrentWindow(), {properties:["openDirectory"]});
See create-react-app issue for the full story
I guess you are using a bundler for your code. In this case, the problem arises, because you don't bundle with the correct target set.
In webpack include target: 'electron-renderer'
into your webpack.config.js
.
In parcel bundle with the correct target via the command line option --target electron
(parcel build yourfile.html --target electron
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With