test(optimizer): add cjs browser field bare import test #7599
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR adds a failing test for #4798, #7301, #7576.
These issues are caused by the same reason.
I investigated this but I could not come up with a good solution.
Additional context
This bug is caused by this line.
idToPkgMap.get(importer)
is undefined through it should have PackageData.vite/packages/vite/src/node/plugins/resolve.ts
Lines 941 to 942 in 5d6ea8e
This
tryResolveBrowserMapping
is called from here.vite/packages/vite/src/node/plugins/resolve.ts
Line 272 in 5d6ea8e
I will try to describe why this is happening only when resolver is used with optimizer.
vite/packages/vite/src/node/optimizer/esbuildDepPlugin.ts
Lines 107 to 149 in 5d6ea8e
idToPkgMap
is constructed correctly.This (sapphi-red@4d7a716) is the solution I came up with but I think this solution has many problems.
pluginData
to check whether it is already called but I feel it would not work if there is other plugins.onResolve
runs two times. For example, if there is aonResolve
which adds@
, the idfoo
will becomefoo@@
.What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).