electron-userland / electron-webpack

Scripts and configurations to compile Electron applications using webpack
https://webpack.electron.build/
903 stars 170 forks source link

electron 13.x #450

Open j3g opened 2 years ago

j3g commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

I think you need

new BrowserWindow({

    webPreferences: {
            nodeIntegration: true,
            contextIsolation: false
  }});
szTheory commented 2 years ago

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

parliament718 commented 2 years ago

@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 commented 2 years ago

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 https://github.com/electron/electron/issues/21457 including some supposed workarounds I haven't tried yet. None of this is officially documented AFAIK.

msemtd commented 1 year ago

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