Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

electron 13.x #450

Open
j3g opened this issue Jul 8, 2021 · 6 comments
Open

electron 13.x #450

j3g opened this issue Jul 8, 2021 · 6 comments

Comments

@j3g
Copy link

j3g commented Jul 8, 2021

Hello fellow users. No maintainer out there so maybe one of you can help me. I'm trying to use all the latest packages and framework right now. Electron 13.x defaults to contextIsolation: false. Because of that I get errors.

Uncaught ReferenceError: require is not defined

I have spent a few days trying to work around this issue. I'm still trying :) Maybe someone can give me assistance. Thank you.

@j3g
Copy link
Author

j3g commented Jul 8, 2021

so none of these electron-wepack quick starts are working.
I did the suggested fix for webpack 5.x ... so I got past that error

@parliament718
Copy link

parliament718 commented Jul 20, 2021

I think you need

new BrowserWindow({
   	
   webPreferences: {
           nodeIntegration: true,
           contextIsolation: false
 }});

@szTheory
Copy link

@parliament718 That will work, but also bypasses some security rules and could lead to vulnerabilities, so be careful.

@parliament718
Copy link

parliament718 commented Jul 28, 2021

@szTheory This may be true but it appears electron-webpack is currently set up with the assumption that nodeIntegration is true.

Here's more info on this https://gist.github.com/earksiinni/053470a04defc6d7dfaacd5e5a073b15
It doesn't seem anybody has come up with a workable solution yet, or at least hasn't shared it.

It's a shame this library isn't maintained and there aren't really any good alternatives. Electron build infrastructure has been the bane of my existence for a while now. Many many hours have been wasted.

@szTheory
Copy link

The approach I am going with is to rip out electron-webpack and just use the TypeScript compiler directly instead of babel. Migrating has been a pain in the butt though because as it turns out even new versions of Electron somehow don't support ES modules, even though the versions of Node they are based on do.

So they are pushing you to these new secure defaults without node integration, even while they leave you only with CommonJS modules. Seems to me like a contradiction. There's a huge Github issue thread about it here electron/electron#21457 including some supposed workarounds I haven't tried yet. None of this is officially documented AFAIK.

@msemtd
Copy link

msemtd commented Oct 11, 2022

The recommended way forward with a supported recent electron version and webpack 5 is to use the webpack template provided with electron-forge, e.g.

yarn create electron-app my-new-app --template=webpack

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants