-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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(optimizer): browser mapping for yarn pnp #6493
Conversation
a4777e8
to
cd19392
Compare
cd19392
to
76a49da
Compare
Everything seems to be working now. Could maintainers please take a look? 🤗 |
I have confirmed that this PR addresses #6693. |
75d8f4b
to
84205e2
Compare
// pass along resolveDir for entries | ||
namespace === 'dep' ? resolveDir : undefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
browser-external proxy from #8338 fixes build-time crashed, but something has changed elsewhere and this workaround doesn't work anymore 🥲 Will have to look into the changes since 2.9.9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, it does work for external dependencies
vfile
here isn't failing at runtime anymore.
But it does not work for local pre-bundled dependencies
This module is loaded in the browser:
https://github.com/swandir/vite-browser-external-pnp/blob/1551d40a3cfb8f59915e43f23a43c87b3682bb7c/dep/node.js#L4
despite being disabled
Okay, I think it's good enough. PnP compatibility issues for external dependencies are solved. Local optimized dependencies with browser mappings are still failing in some cases as I described here. But that's rather edge-casey and can be tackled separately. @bluwy @patak-dev can you please take a look? |
Any chance we could get this merged in for vite@2 as well? We'd like to be able to use yarn's pnp with vite without switching to vite@beta since it's not recommended for production. |
For the time being you can create a patch from this commit. Or pack a tarball from a tag and use it via Yarn's |
@ferm10n Vite 3 will be released as stable this week. |
Description
fix: #1979
Currently, internal module re-mapping via the browser field in package.json during dependency pre-bundling is not supported when is used with Yarn in PnP mode.
This fails to re-map for the browser, and the original node-targeting module is bundled instead.
This happens due to incorrect
importer
being passed toresolver
inesbuildDepPlugin
:vite/packages/vite/src/node/optimizer/esbuildDepPlugin.ts
Lines 59 to 68 in 6ecf9b0
Here the comment states that
resolveDir
is passed for package entries only, however it actually is passed unconditionally in PnP compatonResolve
:vite/packages/vite/src/node/optimizer/esbuildDepPlugin.ts
Lines 210 to 216 in 6ecf9b0
As a result,
tryResolveBrowserMapping
invite:resolve
fails to locate relatedpkg
data, which leads to ignoring internalbrowser
field mappings for a package being pre-bundled.This PR fixed the problem by passing
resolveDir
only for the actual entry modules, which are detected by comparingnamespace
to'dep'
.Here's a CodeSandbox with failing checks: linl.
And here's one with fixed Vite version from this PR: link.
Additional context
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).