Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/gold-fireants-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: always add `@sveltejs/kit` to `noExternal` for ssr build
33 changes: 17 additions & 16 deletions packages/kit/src/exports/vite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,21 +218,6 @@ function kit({ svelte_config }) {

const generated = path.posix.join(kit.outDir, 'generated');

// This ensures that esm-env is inlined into the server output with the
// export conditions resolved correctly through Vite. This prevents adapters
// that bundle later on from resolving the export conditions incorrectly
// and for example include browser-only code in the server output
// because they for example use esbuild.build with `platform: 'browser'`
const noExternal = ['esm-env'];

// Vitest bypasses Vite when loading external modules, so we bundle
// when it is detected to keep our virtual modules working.
// See https://github.com/sveltejs/kit/pull/9172
// and https://vitest.dev/config/#deps-registernodeloader
if (process.env.TEST) {
noExternal.push('@sveltejs/kit');
}

// dev and preview config can be shared
/** @type {import('vite').UserConfig} */
const new_config = {
Expand Down Expand Up @@ -269,7 +254,23 @@ function kit({ svelte_config }) {
]
},
ssr: {
noExternal
noExternal: [
// This ensures that esm-env is inlined into the server output with the
// export conditions resolved correctly through Vite. This prevents adapters
// that bundle later on from resolving the export conditions incorrectly
// and for example include browser-only code in the server output
// because they for example use esbuild.build with `platform: 'browser'`
'esm-env',
// We need this for two reasons:
// 1. Without this, `@sveltejs/kit` imports are kept as-is in the server output,
// and that causes modules and therefore classes like `Redirect` to be imported twice
// under different IDs, which breaks a bunch of stuff because of failing instanceof checks.
// 2. Vitest bypasses Vite when loading external modules, so we bundle
// when it is detected to keep our virtual modules working.
// See https://github.com/sveltejs/kit/pull/9172
// and https://vitest.dev/config/#deps-registernodeloader
'@sveltejs/kit'
]
}
};

Expand Down