Skip to content

Fix require handling with electron; fixes #11599#11603

Merged
sokra merged 1 commit intowebpack:masterfrom
MayaRainer:master
Oct 10, 2020
Merged

Fix require handling with electron; fixes #11599#11603
sokra merged 1 commit intowebpack:masterfrom
MayaRainer:master

Conversation

@MayaRainer
Copy link
Copy Markdown
Contributor

This fixes electron/index.js being bundled as described in #11599, and also fixes electron-renderer to use the correct chunk format, as it is in a browser and not in a module context.

What kind of change does this PR introduce?
Bugfix.

Did you add tests for your changes?
Not yet

Does this PR introduce a breaking change?
No

What needs to be documented once your changes are merged?
Nothing

@jsf-clabot
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.

@webpack-bot
Copy link
Copy Markdown
Contributor

For maintainers only:

  • This needs to be documented (issue in webpack/webpack.js.org will be filed when merged)
  • This needs to be backported to webpack 4 (issue will be created when merged)

@webpack-bot
Copy link
Copy Markdown
Contributor

Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon.

Comment thread lib/config/defaults.js
});
F(output, "chunkFormat", () => {
if (tp) {
if (tp.document) return "array-push";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason behind this change?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and also fixes electron-renderer to use the correct chunk format, as it is in a browser and not in a module context.

It's should be in both contexts. So require() should be available and we can use it to load chunk.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that electron-renderer means a BrowserWindow with nodeIntegration: true.

For a BrowserWindow with nodeIntegration: false you should use target: "web".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The primary reason behind this change was to match previous behaviour. As you can see here, electron-renderer used to use array-push and jsonp, and my changes restore that behaviour.

require() is available, yes; but chunkFormat=commonjs makes it generate a chunk in the format

exports.id = "common";
exports.ids = ["common"];
exports.modules = {
...

which doesn't work because there is no module context in the browser and so we get a

common.js:1 Uncaught ReferenceError: exports is not defined

regardless of whether nodeIntegration is turned on (unless I've overlooked something else, of course).

@webpack-bot
Copy link
Copy Markdown
Contributor

Hi @MayaWolf.

Just a little hint from a friendly bot about the best practice when submitting pull requests:

Don't submit pull request from your own master branch. It's recommended to create a feature branch for the PR.

You don't have to change it for this PR, just make sure to follow this hint the next time you submit a PR.

@sokra sokra merged commit bfc35d6 into webpack:master Oct 10, 2020
@sokra
Copy link
Copy Markdown
Member

sokra commented Oct 10, 2020

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants