Conversation
|
Do you have an example where this could happen? Svelte recently support using clsx internally, but it's part of its runtime and should already be optimized together. |
|
Yep! Not really a minimal repro, but running git clone https://github.com/GauBen/gautier.dev
cd gautier.dev
yarn
yarn devShould display the following: ❯ yarn dev
Forced re-optimization of dependencies
VITE v6.0.7 ready in 795 ms
➜ Local: http://localhost:5173/
➜ Network: use --host to expose
➜ press h + enter to show help
{
message: 'Bad credentials',
documentation_url: 'https://docs.github.com/graphql',
status: '401'
}
9:42:46 AM [vite] (client) ✨ new dependencies optimized: clsx
9:42:46 AM [vite] (client) ✨ optimized dependencies changed. reloading
{
message: 'Bad credentials',
documentation_url: 'https://docs.github.com/graphql',
status: '401'
} |
|
only seems to happen with vite6 |
import 'svelte/internal/disclose-version';
import 'svelte/internal/flags/legacy';
import * as $ from 'svelte/internal/client';
var root = $.template(`<h1></h1>`);
export default function App($$anchor) {
let name = 'world';
var h1 = root();
$.set_class(h1, $.clsx(['foo', 'bar']));
h1.textContent = `Hello ${name ?? ''}!`;
$.append($$anchor, h1);
}svelte generates code that imports clsx, ultimately it is imported here: i wonder how vite5 is able to detect this eagerly. clsx was only added in a later version of svelte5, so to avoid issues with earlier versions, the inject would have to check if clsx is a dependency of svelte. But ideally we find out why vite6 behaves differently (or if the same can happen in vite5 and it was just my testing that was off). |
|
had another look, whats even more puzzling is that clsx doesn't need to be optimized, it is not using "exports": {
".": {
"import": {
"types": "./clsx.d.mts",
"default": "./dist/clsx.mjs"
},so adding this to optimizeDeps.include is really weird. i wonder how it is determined that it needs optimization in the first place. This feels like a vite issue the more i think about it. |
|
if we were to add it, i think it would have to be in the form |
|
because it does export esm and is single file anyways we could also put it in optimizeDeps.exclude as optimizing it won't do anything of value. |
|
unfortunately excluding does not work because vite import analysis then can't find it in the optimized svelte. 😞 |
|
Be careful, it looks like you fell into a rabbit hole 😄 |
|
looked into this again and i wasn't able to reproduce with pnpm only with npm. wtf |
|
closing in favor of #1124 |
Small fix to address these small log lines: