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 Forge's Webpack plugin errantly depends on node require #2618

Open
3 tasks done
MynockSpit opened this issue Nov 19, 2021 · 2 comments
Open
3 tasks done

Electron Forge's Webpack plugin errantly depends on node require #2618

MynockSpit opened this issue Nov 19, 2021 · 2 comments
Labels
bug plugin/webpack Issues or pull requests related to first-party webpack plugins/templates

Comments

@MynockSpit
Copy link

Pre-flight checklist

  • I have read the contribution documentation for this project.
  • I agree to follow the code of conduct that this project uses.
  • I have searched the issue tracker for a bug that matches the one I want to file, without success.

Electron Forge version

6.0.0-beta.61

Electron version

v16.0.0

Operating system

macOS 12.0.1

Last known working Electron Forge version

N/A

Expected behavior

Electron Forge should not depend on node's require unless both nodeIntegration: true and contextIsolation: false.

Actual behavior

Electron Forge throws an error in the dev-server when you attempt to use nodeIntegration as described here: https://www.electronforge.io/config/plugins/webpack#node-integration

You can work around this for the dev-server by adding target: ['web', 'electron-renderer'] to your renderer webpack config, but it doesn't fix It for production builds:

Screen Shot 2021-11-19 at 11 50 22 AM

Screen Shot 2021-11-19 at 11 50 36 AM

Steps to reproduce

  1. Create a new electron app using the typescript-webpack plugin.
    npx create-electron-app my-new-app --template=typescript-webpack
  2. Add webPreferences: { nodeIntegration: true } to the new BrowserWindow call in index.ts
  3. Add nodeIntegration: true to the forge config in the package.json.
  4. Start the new app, observe the error.

As mentioned above, you can work around this for the dev-server by adding target: ['web', 'electron-renderer'] to your renderer webpack config, but it doesn't fix It for production builds.

To fully fix this, you need to set contextIsolation: false in the new BrowserWindow call in index.ts which is not ideal.

Additional information

This may be a bug in vercel/webpack-asset-relocator-loader and not Electron Forge, but it should at least be documented.

@MynockSpit MynockSpit added the bug label Nov 19, 2021
@RoyYangS
Copy link

RoyYangS commented Mar 2, 2022

Found this bug also. If someone does not want to open { nodeIntegration: true }, another workaround is to get the page url from ipcMain side by adding an ipcMain handle method to return the page urls.

but I think it is still a bug that needs to be fixed.

@iCyris
Copy link

iCyris commented Dec 16, 2022

I also encountered this problem, is there any latest solution? Thanks.

@erickzhao erickzhao added the plugin/webpack Issues or pull requests related to first-party webpack plugins/templates label Dec 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug plugin/webpack Issues or pull requests related to first-party webpack plugins/templates
Projects
None yet
Development

No branches or pull requests

4 participants