-
-
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
Transitive dependency results in Vite build error while direct dependency does not #8141
Comments
The direct reason is The behavior difference between direct and transitive dep comes from the difference of Vite's resolver and esbuild's resolver. esbuild's one fallbacks to another entry point if the browser field points to a file which does not exist. Vite's one does not do that. |
@sapphi-red Thanks for the answer. If I understood you correctly, ESBuild resolves transitive dependencies, while Vite resolves direct dependencies. If that's the case, doesn't that mean that you meant it the other way around and that Vite does fallback and ESBuild does not? Also, is there a reason why both prefer the |
Partially yes.
I think this is the reason. |
Thanks for the context. |
The formats are same. browser ESM stands for ESM with browser specific code (like |
That makes sense. Thanks for all the help! Closing this as the issue lies in |
Describe the bug
When adding a dependency @cognite/3d-web-parser in
package.json
and importing something from it, everything runs fine.However, when adding a dependency @cognite/3d-viewer which itself depends on
@cognite/3d-web-parser
and including something from@cognite/3d-viewer
, Vite spits out a build error that it can not resolve the dependency@cognite/3d-web-parser
with the below error message:[plugin vite:dep-scan] Failed to resolve entry for package "@cognite/3d-web-parser". The package may have incorrect main/module/exports specified in its package.json: Failed to resolve entry for package "@cognite/3d-web-parser". The package may have incorrect main/module/exports specified in its package.json.
When looking at the
@cognite/3d-web-parser#package.json#module
entry, it does point to an existingindex.es.js
file that does seem to be in ESM format.It might have something to do w/
yarn
installing@cognite/3d-web-parser
undernode_modules/@cognite/3d-viewer/node_modules/3d-web-parser
instead of installing it under@cognite/3d-web-parser
.I'm not sure why Yarn doesn't do that, though I'd also think that that shouldn't pose a problem to Vite.
Reproduction
https://github.com/Robin-Hoodie/vite-resolve-failure-repro
System Info
Used Package Manager
yarn
Logs
Validations
The text was updated successfully, but these errors were encountered: