-
-
Notifications
You must be signed in to change notification settings - Fork 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
Automatically add Svelte component libraries to ssr.noExternal #904
Comments
It's a workaround for getting Vite to bundle the dependencies into the application for serverless use. The targets that our current adapters use completely skip the platform's bundling step, so we have to do it ourselves. For example, our use of This absolutely feels like something the adapters should have control over especially because it's counterproductive for A really unfortunate related issue with this configuration is the difference between |
My thinking is that we could expose an API that essentially just runs |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I filed a separate ticket to track the |
@GrygrFlzr metioned that some component libraries like From my quick peek at it, both libraries provide both a |
I have a couple of observations:
I cloned Vite, and made a change to run to transform all js modules to ESM:
This transforms all .js files, even those that are already ESM, but esbuild doesn't modify the code in that case. Both carbon-components-svelte and svelte-materialify are in my package.json "dependencies". Both 'npm run dev' and npm build/start appear to work. Does this sound like a Vite bug, i.e., something they may have overlooked? I'm new at all this, and you may already know the source of this issue, so please excuse me if I'm not adding any value to this discussion. |
It might be worth creating a PR to vite with your modifications. It should be a good starting point for improving compatibility with packages that use CJS somewhere in their dependency tree. |
I added the following issue: vitejs/vite#3024 An afterthought -- not sure what you meant by a PR. I'm very new to Open Source and Github infrastructures. |
PR is a commonly used acronym for Pull Request. Thanks for the investigation on this! |
@benmccann What exactly i should do to fix this error with
Reproduce:
my
Solutions from FAQ
Something like that?
|
@GreenRobot777 -- I created a project as you described -- placing carbon-components-svelte in 'dependencies'. I get the error:
I'm not sure why you get your error message instead of mine. Regardless, the module "clipboard-copy" is a cjs module, and will cause the error as I described. I had submitted an issue to Vite -- even though 'Datatable' may not use 'clipboard-copy', the dev server loads all dependencies of 'carbon-components-svelte'. When I do an 'pnpm run build' and 'pnpm run start', it works properly -- due to tree shaking. Here's my environment:
|
@GreenRobot777 This issue was already discussed in carbon-components: see the issue |
* force Vite to bundle component libraries in SSR - fixes #904 * get things working * lockfile, again * update docs * Update documentation/faq/70-packages.md Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com> * remove ssr config from svelte.config.cjs * changeset Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
@Rich-Harris I'm reading through this issue trying to understand what the resolution was. Basically is this still needed in the config or will it not be necessary? vite: {
ssr: {
noExternal: Object.keys(pkg.dependencies || {})
}
} |
It's not necessary. Go ahead and remove it and (hopefully) nothing bad will happen. |
@benaltair See https://kit.svelte.dev/faq#packages.
|
Thanks @babichjacob and @janosh 🙏🏻 |
Is your feature request related to a problem? Please describe.
Vite will exclude many
node_modules
packages from the SSR bundle it generates, using a set of heuristics. While they're subject to change, those heuristics typically exclude Svelte component libraries from the bundle, and so we need to explicitly add them tossr.noExternal
, as in #806 or the kit.svelte.dev config.Describe the solution you'd like
A convention exists for declaring a package to be a component library —
pkg.svelte
. It's not used universally (e.g. Svelte GL and site-kit don't use it, which I was slightly surprised about. not sure what i was thinking) but with #518 we can make it more of a standard.We could forcibly add packages with a
pkg.svelte
tossr.noExternal
, in addition to any values the user may have specified. This would reduce the number of bugs along the lines of #806.Relatedly, I can't remember the reason we added the current
ssr.noExternal
block to the template...kit/packages/create-svelte/template/svelte.config.cjs
Lines 15 to 19 in ccb8825
Describe alternatives you've considered
Solve it with documentation. We could also force
devDependencies
to always be bundled rather thandependencies
, and expect people to understand the difference.How important is this feature to you?
Not solving this one way or another is going to cause people to get mad at us.
The text was updated successfully, but these errors were encountered: