What is Electron?
Electron is a framework for creating native applications. It's open-source and cross-platform. If you already know Jav...
For further actions, you may consider blocking this person and/or reporting abuse
Once I set nodeIntegration: false, I get this error:
That's weird, what if you don't set nodeIntegration? does the error still there?
I "solved" by changing in webpack.react.config.js :
target:
//"electron-renderer",
"web",
Does this change causes some side-effects?
Hi, maybe you will have problems when you build your app since that is what
electron-renderer
is used for. Do you have a repo to see your code? do you mind sharing it on the issue you opened? thanks.I loaded everything here: github.com/raphael10-collab/electr...
As you can see, I didn't anything special: it's your app, where the only differences are these ones:
electron/main.ts :
webPreferences: {
nodeIntegration: false
webpack.react.config.js :
target:
//"electron-renderer",
"web",
If you revert back webpack.react.config.js from "web" to "electron-renderer", you should get the error:
"Uncaught ReferenceError: require is not defined at Object.url", when nodeIntegration is kept to false. If nodeIntegration is set to true, the problem disappears. But this is not what we are looking for, because we would like to have a more secure electron-react-typescript app with nodeIntegration:false
I loaded everything on here: github.com/raphael10-collab/electr...
In your app I just modified these two things:
webPreferences:
nodeIntegration: true
webpack.react.config.js :
If you revert back target: "web" to "electron-renderer" (the correct setting), you should get the error: "Uncaught ReferenceError: require is not defined at Object.url"
And if you set nodeIntegration:true the problem disappears. But if we want to keep our app more secure, we ought to keep nodeIntegration:false
Removing the devServer part of webpack.react.config.js :
while keeping target: "electron-renderer" make it work also with nodeIntegration: false
webpack.react.config.js :
This is the new repo: github.com/raphael10-collab/Electr...
git cloning it, and then executing yarn electron .
I get the app without any errors
I wrote this github's issue about this problem: github.com/elisealcala/electron-re...
I think it's an important issue, because if we want, for strict security reasons, keep nodeIntegration:false + contextIsolation:true, we must solve it
Once i set nodeIntegration: true again, the error disappears. So It Is clearly related to nodeIntegration: false
So... my question is: how to solve the problem, while keeping nodeIntegration:false + contextIsolation:true for strict security reasons?
Nice and easy tutorial.
Do you plan to continue it with adding more electron based functionality (to tease some capability of the electron itself) or discuss the webpack configuration to let even the beginners understand why-what-where to do in it?
Hey, I could write about the webpack configuration, maybe a detailed and general view to understand how it works.
I thought about making more electron posts, maybe a serie about creating a complete app.
Hey, really greate post. Exactly what I need.
Can you also describe how to pack it with electron-builder or electron-packager?
Thx in advice.
Hi, sorry for the late reply, if you check the repo the configuration to pack it with
electron-builder
is already there.Ok now this work, but after i run
dev:electron
I got an empty planck white page ?! imageHi, great article, thanks a lot !
I just have a question, I'm struggled with a simple import of .png after the complete installation. Everything works great, including adding styled components and other packages, but I simply can't import an image file, I have an error : "no loaders configured for this file". I guess I have to edit the Webpack conf, but don't know how :(
Can you help me ?
It can do wonders, VS Code as an example :)
Hi, great article, thank you!
I was wondering if babel is really necessary. Couldn't we use the the normal typescript transpiler for that? After all, we don't need to be compatible to different browsers if we ship our own browser.
Hi, I haven't tried it but I think it could work.
Just what I need. You are my hero ❤️
Is it possible to start both react and electron with just one command?
hi!
just add the concurrently npm package to the dev dependencies and your scripts should be like this:
"scripts": {
"dev": "concurrently --success first \"npm run dev:electron\" \"npm run dev:react\" -k",
"dev:electron": "cross-env NODE_ENV=development webpack --config webpack.electron.config.js --mode development && electron .",
"dev:react": "cross-env NODE_ENV=development webpack serve --config webpack.react.config.js --mode development && electron ."
},
As you can see, the dev script calls the concurrently command and the commands that you need to execute concurrently have to be put one after the other among quotation marks ("), escaping them, obviously.
contentBase
andpublicPath
are invalid options in devServer.