-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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(resolve): use only root package.json as exports source #11259
Conversation
69808a3
to
de249e7
Compare
/ecosystem-ci run |
📝 Ran ecosystem CI: Open
|
Looks like this broke |
I'm investigating this - gonna have to get back to it later but so far I've noticed one difference. Without this patch, I get such values in this function: {
pkgId: 'preact',
rootPkg: null,
id: 'preact/jsx-dev-runtime',
importer: undefined
} whereas with this patch |
06e400a
to
7a11ec1
Compare
I got almost to the bottom of the problem - and I'm afraid that I'm not sure how to solve this because Vite's resolver is fundamentally incompatible with how With the old code, you don't consider vite/packages/vite/src/node/plugins/resolve.ts Lines 716 to 718 in f12a1ab
This happens because
since the "root" has to be determined as preact/hooks instead of preact .
So you try to resolve this with vite/packages/vite/src/node/plugins/resolve.ts Lines 928 to 932 in f12a1ab
But you end up overriding, what should be the "final" return value, with the vite/packages/vite/src/node/plugins/resolve.ts Lines 983 to 991 in f12a1ab
So you actually end up resolving the commonjs file for With my patch though... we end up using vite/packages/vite/src/node/plugins/resolve.ts Line 1116 in f12a1ab
Both |
Probably a fix could look like this:
I don't understand why you need this overriding logic in the first place though. From my PoV... it just shouldn't be there. |
Thanks for digging into this! I agree that the If we re-apply #11234 (the fix), I believe that should fix the preact issue? If so, I think we could land both of these fixes and try to figure out the Vue issue in #11114, in the next Vite minor. The current behaviour deviates from Node resolution algorithm so we can consider this a bug fix. |
Here's the run with this PR + #11234: https://github.com/vitejs/vite-ecosystem-ci/actions/runs/3822217463. We got the same fail from Histoire (as few weeks ago) which I believe stems from |
Not necessarily - but that's super hard to tell without actually trying it. The issue with Preact is that you end up loading both CJS and ESM of IIRC the CJS file is loaded by
Somehow you manage to load the CJS file for |
Thanks for the explanation! Yeah that makes sense as to why it's failing now. I've also tested it in the comment above yours (I sent that 1 minute before yours 😬), and it seems to fix it. I think we should merge this in 4.1, which the beta should come soon this week or the next. I'll loop in Patak when he gets back and we can coordinate this further. |
Hey, I'm back 👋🏼 |
) Co-authored-by: bluwy <[email protected]>
Description
I'm Emotion's maintainer and got this bug report.
I've narrowed this down to our
@emotion/styled/base
not being resolved correctly by Vite. For compatibility reasons we have@emotion/styled/base/package.json
in our package (can be viewed here) - from which Vite tries to readpackage.json#exports
. However, this is not how the node resolution algorithm works.exports
are only read from the rootpackage.json
and we have appropriate entries there (see here).The pseudo algorithm for this resolution can be found in the node docs here. We should focus on the
LOAD_PACKAGE_EXPORTS
procedure here - note how its 3rd step is this:This doesn't loop anyhow, nor it doesn't include
SUBPATH
here. This means thatexports
are only read from the rootpackage.json
This can be verified against the node's runtime or in their source code here. Note how, in here,
/base
becomes theexpansion
and that isn't used anyhow bypkgPath
,pkg
andpackageExportsResolve
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).