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

setting target 'web' in renderer webpack config also make the preload script compile with 'web' target #1852

Closed
3 tasks done
vazra opened this issue Jul 20, 2020 · 2 comments · Fixed by #1853
Closed
3 tasks done
Labels

Comments

@vazra
Copy link
Contributor

vazra commented Jul 20, 2020

Preflight Checklist

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

Issue Details

  • Electron Forge Version:
    • 6.0.0-beta.52
  • Electron Version:
    • v9.1.0
  • Operating System:
    • macOS 10.14.6
  • Last Known Working Electron Forge version::
    • --

Expected Behavior

preload script should use the target: 'electron-preload',

Actual Behavior

I am not sure if this is an expected behaviour or bug. I am porting my electron app to electron forge. In the app I have the nodeIntegration false and I expose some native features with a preload script. So basically the renderer will target will be similar to a modern browser.

When I tried the current default webpack configuration, the compiling fails with errors like

Uncaught ReferenceError: require is not defined
    at Object.events (external "events":1)
    at __webpack_require__ (bootstrap:789)

with which I came to a conclusion that the webpack is compiling the renderer code similar to a node environment, which actually is not a node environment as node integration is false (refer this comment)

then I tried setting target to web in webpack.renderer.config.js

module.exports = {
  ...
  target: 'web',
  ...
}

that led me to this issue.

setting target in renderer config sets the same target for preload as well. when I dig into the codebase of Webpack plugin
this line 191 in this function is setting the same web target for preload as well.
https://github.com/electron-userland/electron-forge/blob/d025878664a662a2c35cd1e140444b36a9f8dabb/packages/plugin/webpack/src/WebpackConfig.ts#L169-L191

Is this an expected behaviour? I think it's better to set target: 'electron-preload', for preload in this case as well.

To Reproduce

  • I've explained the use case above. If a sample repo is required, I can create one.

Additional Information

N/A

@vazra vazra added the bug label Jul 20, 2020
@vazra
Copy link
Contributor Author

vazra commented Jul 20, 2020

@malept @MarshallOfSound any thoughts?

@vazra
Copy link
Contributor Author

vazra commented Jul 20, 2020

if anyone want a workaround for this you can use https://www.npmjs.com/package/moc-electron-forge-pluginwebpack

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