diff --git a/.changeset/lucky-apples-breathe.md b/.changeset/lucky-apples-breathe.md new file mode 100644 index 000000000000..6804bcd64e6e --- /dev/null +++ b/.changeset/lucky-apples-breathe.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +[fix] ensure export conditions are resolve through Vite diff --git a/packages/kit/src/exports/vite/build/utils.js b/packages/kit/src/exports/vite/build/utils.js index 6cab3727d474..08f3538571f5 100644 --- a/packages/kit/src/exports/vite/build/utils.js +++ b/packages/kit/src/exports/vite/build/utils.js @@ -138,7 +138,16 @@ export function get_build_setup_config({ config, ssr }) { exclude: ['@sveltejs/kit'] }, ssr: { - noExternal: ['@sveltejs/kit'] + noExternal: [ + // TODO document why this is necessary + '@sveltejs/kit', + // 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 to resolve 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' + ] }, worker: { rollupOptions: {