@@ -218,21 +218,6 @@ function kit({ svelte_config }) {
218
218
219
219
const generated = path . posix . join ( kit . outDir , 'generated' ) ;
220
220
221
- // This ensures that esm-env is inlined into the server output with the
222
- // export conditions resolved correctly through Vite. This prevents adapters
223
- // that bundle later on from resolving the export conditions incorrectly
224
- // and for example include browser-only code in the server output
225
- // because they for example use esbuild.build with `platform: 'browser'`
226
- const noExternal = [ 'esm-env' ] ;
227
-
228
- // Vitest bypasses Vite when loading external modules, so we bundle
229
- // when it is detected to keep our virtual modules working.
230
- // See https://github.com/sveltejs/kit/pull/9172
231
- // and https://vitest.dev/config/#deps-registernodeloader
232
- if ( process . env . TEST ) {
233
- noExternal . push ( '@sveltejs/kit' ) ;
234
- }
235
-
236
221
// dev and preview config can be shared
237
222
/** @type {import('vite').UserConfig } */
238
223
const new_config = {
@@ -269,7 +254,23 @@ function kit({ svelte_config }) {
269
254
]
270
255
} ,
271
256
ssr : {
272
- noExternal
257
+ noExternal : [
258
+ // This ensures that esm-env is inlined into the server output with the
259
+ // export conditions resolved correctly through Vite. This prevents adapters
260
+ // that bundle later on from resolving the export conditions incorrectly
261
+ // and for example include browser-only code in the server output
262
+ // because they for example use esbuild.build with `platform: 'browser'`
263
+ 'esm-env' ,
264
+ // We need this for two reasons:
265
+ // 1. Without this, `@sveltejs/kit` imports are kept as-is in the server output,
266
+ // and that causes modules and therefore classes like `Redirect` to be imported twice
267
+ // under different IDs, which breaks a bunch of stuff because of failing instanceof checks.
268
+ // 2. Vitest bypasses Vite when loading external modules, so we bundle
269
+ // when it is detected to keep our virtual modules working.
270
+ // See https://github.com/sveltejs/kit/pull/9172
271
+ // and https://vitest.dev/config/#deps-registernodeloader
272
+ '@sveltejs/kit'
273
+ ]
273
274
}
274
275
} ;
275
276
0 commit comments