Skip to content

fix: respect mainFields when resolving browser/module field (fixes #8659)#10071

Merged
patak-cat merged 4 commits intovitejs:mainfrom
sapphi-red:fix/respect-mainfields
Sep 23, 2022
Merged

fix: respect mainFields when resolving browser/module field (fixes #8659)#10071
patak-cat merged 4 commits intovitejs:mainfrom
sapphi-red:fix/respect-mainfields

Conversation

@sapphi-red
Copy link
Copy Markdown
Member

Description

Because resolve.mainFields's default value does not include 'browser', I added a special !browser value to avoid a breaking change.
https://vitejs.dev/config/shared-options.html#resolve-mainfields
In Vite 4, I think we could change the default value to ['browser', 'module', 'jsnext:main', 'jsnext'].

fixes #8659

Additional context


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@sapphi-red sapphi-red added the p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority) label Sep 11, 2022
@patak-cat
Copy link
Copy Markdown
Member

I would prefer to directly wait for Vite 4 and fix this instead of adding the temporal !browser option, but if @sheremet-va @antfu thinks fixing this is important enough for Vitest, I think you did a good call here Sapphi.

@patak-cat patak-cat requested a review from antfu September 11, 2022 18:34
@antfu
Copy link
Copy Markdown
Member

antfu commented Sep 12, 2022

I think indeed the current behavior is a kinda flaw and the fix makes a lot of sense. As for the shipping, I think we could have the workaround (maybe via an option instead of a magic !browser?), but I'll leave it to @sheremet-va to decide.

@sheremet-va
Copy link
Copy Markdown
Member

sheremet-va commented Sep 12, 2022

I think indeed the current behavior is a kinda flaw and the fix makes a lot of sense. As for the shipping, I think we could have the workaround (maybe via an option instead of a magic !browser?), but I'll leave it to @sheremet-va to decide.

I was also thinking about some resolve.browserField option or something similar. !browser feels magicky.

JFI: there is also #9860 PR that fixes similar problem.

@patak-cat patak-cat added this to the 3.2 milestone Sep 12, 2022
@patak-cat
Copy link
Copy Markdown
Member

Thanks for the feedback. @sapphi-red what do you think about renaming to resolve.browserField and release it in 3.2?

@sapphi-red
Copy link
Copy Markdown
Member Author

Yeah, sounds good to me. I've update the PR 👍

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

Labels

p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vite ignores resolve.mainFields, if ssr is false

4 participants