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 👋🏼 |
Description
I'm Emotion's maintainer and got this bug report.
I've narrowed this down to our
@emotion/styled/basenot being resolved correctly by Vite. For compatibility reasons we have@emotion/styled/base/package.jsonin our package (can be viewed here) - from which Vite tries to readpackage.json#exports. However, this is not how the node resolution algorithm works.exportsare only read from the rootpackage.jsonand 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_EXPORTSprocedure here - note how its 3rd step is this:This doesn't loop anyhow, nor it doesn't include
SUBPATHhere. This means thatexportsare only read from the rootpackage.jsonThis can be verified against the node's runtime or in their source code here. Note how, in here,
/basebecomes theexpansionand that isn't used anyhow bypkgPath,pkgandpackageExportsResolveWhat is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123).