-
-
Notifications
You must be signed in to change notification settings - Fork 105
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
Improve handling for hybrid svelte packages in automatic dependency optimization #162
Comments
Issues in other repos: |
Another alternative: We change nothing in |
@benmccann I've updated the description with some info on why the packages fail. For For
The other node-only deps only exported CJS code and Vite worked fine with them (Likely because the prebundling One solution I had in mind was to implement our own scanner and detect used dependencies ourselves, instead of the current implementation that puts all the library's Otherwise, ideally we could fix by letting Vite do all the hard work of nested optimization by default, addressing |
In Routify, packages such as |
Yeah, but it's vite-plugin-svelte instead of vite making the assumption since currently it thinks that all |
yes, but it is vite-plugin-svelte making this assumption, not vite itself. |
Someone had tried using |
Is there an issue on vite for them assuming all deps are to be optimised? |
I don't think so, pre-bundling/optimization is only for client-side deps only. Currently, However, I may have a solution that should fix all these issues directly in |
Would this only resolve svelte dependancies? what happens to deps without a |
The whole automatic dependency optimization handling is only done for dependencies with "svelte" in their package.json. Regular non-svelte dependencies are handled by vite itself. Svelte dependencies are special because we have to exclude them from optimization to avoid errors. And then reinclude their cjs dependencies to avoid subsequent errors 🙈 . Ideally vite's optimizer would be able to understand svelte dependencies correctly (with the help of vite-plugin-svelte or internal fixes in vite), but until we get there, we can only try to make it work as good as possible. The fix proposed by @bluwy prevents reincluding dependencies that would cause the errors mentioned above, which is good because less users would be affected. But it's not the long term solution we're after. And it requires additional parsing of package.json files, so it affects startup time of vite-plugin-svelte, esp. in projects with many dependencies. |
Describe the problem
Some svelte packages are hybrids and could contain dependencies on node-only packages.
These packages then can fail in vite's optimizer with an error like
Failed to resolve entry for package "foo > bar". The package may have incorrect main/module/exports specified in its package.json
Currently known hybrids:
@roxi/routify
- error caused by@types/node
(onlytypes
entry),cheap-watch
,rollup-pluginutils
(export esm and used node builtin modules)@carbon/charts-svelte
- error caused by@carbon/telemetry
(onlybin
entry)Describe the proposed solution
Alternatives considered
optimizeDeps.exclude
in vite configImportance
would make my life easier
The text was updated successfully, but these errors were encountered: