diff --git a/.changeset/flat-hairs-love.md b/.changeset/flat-hairs-love.md new file mode 100644 index 000000000000..e45f658a3ae7 --- /dev/null +++ b/.changeset/flat-hairs-love.md @@ -0,0 +1,5 @@ +--- +"@sveltejs/kit": patch +--- + +fix: exclude server files from optimizeDeps.entries diff --git a/packages/kit/src/exports/vite/index.js b/packages/kit/src/exports/vite/index.js index c91055ba9aa7..96d90bd3ed2a 100644 --- a/packages/kit/src/exports/vite/index.js +++ b/packages/kit/src/exports/vite/index.js @@ -293,7 +293,10 @@ async function kit({ svelte_config }) { cors: { preflightContinue: true } }, optimizeDeps: { - entries: [`${kit.files.routes}/**/+*.{svelte,js,ts}`], + entries: [ + `${kit.files.routes}/**/+*.{svelte,js,ts}`, + `!${kit.files.routes}/**/+*server.*` + ], exclude: [ '@sveltejs/kit', // exclude kit features so that libraries using them work even when they are prebundled diff --git a/packages/kit/test/apps/dev-only/test/test.js b/packages/kit/test/apps/dev-only/test/test.js index 346043f09d80..6872157303ed 100644 --- a/packages/kit/test/apps/dev-only/test/test.js +++ b/packages/kit/test/apps/dev-only/test/test.js @@ -107,14 +107,14 @@ test.describe('Vite', () => { expect(manifest).toHaveProperty('optimized.e2e-test-dep-page-universal'); }); - test('optimizes +page.server.js dependencies', async ({ page }) => { + test('skips optimizing +page.server.js dependencies', async ({ page }) => { await page.goto('/'); await page.getByText('hello world!').waitFor(); const manifest_path = path.join(__dirname, '../node_modules/.vite/deps/_metadata.json'); const manifest = JSON.parse(fs.readFileSync(manifest_path, 'utf-8')); - expect(manifest).toHaveProperty('optimized.e2e-test-dep-page-server'); + expect(manifest).not.toHaveProperty('optimized.e2e-test-dep-page-server'); }); test('optimizes +layout.svelte dependencies', async ({ page }) => { @@ -137,14 +137,14 @@ test.describe('Vite', () => { expect(manifest).toHaveProperty('optimized.e2e-test-dep-layout-universal'); }); - test('optimizes +layout.server.js dependencies', async ({ page }) => { + test('skips optimizing +layout.server.js dependencies', async ({ page }) => { await page.goto('/'); await page.getByText('hello world!').waitFor(); const manifest_path = path.join(__dirname, '../node_modules/.vite/deps/_metadata.json'); const manifest = JSON.parse(fs.readFileSync(manifest_path, 'utf-8')); - expect(manifest).toHaveProperty('optimized.e2e-test-dep-layout-server'); + expect(manifest).not.toHaveProperty('optimized.e2e-test-dep-layout-server'); }); test('optimizes +error.svelte dependencies', async ({ page }) => {