Skip to content
Open
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
7 changes: 7 additions & 0 deletions .changeset/fix-vitest-base-path-conflict.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@sveltejs/kit': patch
---

fix: don't apply `paths.base` to Vite config when running under Vitest

When `kit.paths.base` was set to a prefix of the project's filesystem path (e.g. `/Users`), Vite would strip that prefix from the URLs vite-node uses to fetch modules over HTTP, causing `ERR_MODULE_NOT_FOUND` failures. Under Vitest, `base` is now forced to `/` so module resolution works regardless of the configured base path.
7 changes: 6 additions & 1 deletion packages/kit/src/exports/vite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,12 @@ async function kit({ svelte_config }) {
} else {
new_config = {
appType: 'custom',
base: kit_paths_base,
// When running under Vitest, don't apply kit.paths.base — vite-node
// serves filesystem modules over HTTP and Vite will strip the base
// prefix from those URLs, breaking module resolution when the base
// happens to match the start of the project path (e.g. "/Users").
// See https://github.com/sveltejs/kit/issues/13737
base: process.env.VITEST ? '/' : kit_paths_base,
build: {
rollupOptions: {
// Vite dependency crawler needs an explicit JS entry point
Expand Down
Loading