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

fix(template-vite): incorrectly bundling browser entrypoints #3278

Merged
merged 2 commits into from
Aug 8, 2023

Conversation

markspolakovs
Copy link
Contributor

@markspolakovs markspolakovs commented Jul 23, 2023

  • I have read the contribution documentation for this project.
  • I agree to follow the code of conduct that this project follows, as appropriate.
  • [n/a] The changes are appropriately documented (if applicable).
  • [n/a] The changes have sufficient test coverage (if applicable).
  • [n/a] The testsuite passes successfully on my local machine (if applicable).

Summarize your changes:

In some cases browserField: false in the vite.main.config.js is not sufficient to ensure that the Node version of a package is bundled (or rather, the browser version is not bundled) - in particular where the package uses conditional exports, because Vite's resolver favours conditions over the browser field:

Note this takes lower precedence than conditional exports resolved from the exports field: if an entry point is successfully resolved from exports, the main field will be ignored.

This PR ensures that we set the node condition, which also makes Vite not load the browser version in certain cases.

I've tested this locally using the ws package: before this change it would throw an error when used from the main process (because it has a browser entrypoint that throws), while it doesn't with this change applied to my config.

@markspolakovs markspolakovs requested a review from a team as a code owner July 23, 2023 20:59
@erickzhao erickzhao changed the title fix(template/vite): incorrectly bundling browser entrypoints fix(template-vite): incorrectly bundling browser entrypoints Jul 28, 2023
Copy link
Member

@caoxiemeihao caoxiemeihao left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@erickzhao erickzhao merged commit fd1ed4b into electron:main Aug 8, 2023
3 checks passed
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

Successfully merging this pull request may close these issues.

3 participants