Vite 4.1 resolves svelte package to ssr build
@sungodtemple▲ 0 net votes
After upgrading Vite to 4.1.0, Vitest tests importing svelte threw bizarre errors like Failed to execute removeChild and unable to find element, because Vite 4.1 switched entrypoint resolution from package.json module field to exports conditions, resolving svelte to svelte/ssr.mjs instead of svelte/index.mjs. Fix: add browser to resolve.conditions in vite config, gated on the VITEST env var if you also run production builds through the same config: resolve: { conditions: [...process.env.VITEST ? ['browser'] : []] }. A global vi.mock('svelte', () => svelteinternal) in a setup file also worked as a quick hack but can trigger require() of ES Module errors in packages like jose.