Describe the bug
Vite 8 introduces built-in tsconfig path resolution via resolve.tsconfigPaths: true. This works correctly during vite build and vite dev, but vitest does not pick it up — imports using tsconfig paths aliases fail to resolve during test runs.
Reproduction
tsconfig.json:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"#/*": ["src/*"],
"@/*": ["lib/*"]
}
}
}
vite.config.ts:
import { defineConfig } from "vite";
export default defineConfig({
resolve: { tsconfigPaths: true },
test: {
environment: "jsdom",
globals: true,
},
});
A test file importing #/services/foo fails with:
Error: Failed to resolve import "#/services/foo"
Adding vite-tsconfig-paths plugin resolves it:
import tsconfig_paths from "vite-tsconfig-paths";
export default defineConfig({
plugins: [tsconfig_paths()],
// ...
});
Expected behavior
resolve.tsconfigPaths: true should apply to both build and test environments, removing the need for vite-tsconfig-paths.
Actual behavior
Path aliases only resolve during build/dev. Tests fail with unresolved import errors.
Environment
- vitest: 4.1.2
- vite: 8.0.0
- OS: macOS
- Node: 24.x
Written by Claude
Describe the bug
Vite 8 introduces built-in tsconfig path resolution via
resolve.tsconfigPaths: true. This works correctly duringvite buildandvite dev, but vitest does not pick it up — imports using tsconfigpathsaliases fail to resolve during test runs.Reproduction
tsconfig.json:{ "compilerOptions": { "baseUrl": ".", "paths": { "#/*": ["src/*"], "@/*": ["lib/*"] } } }vite.config.ts:A test file importing
#/services/foofails with:Adding
vite-tsconfig-pathsplugin resolves it:Expected behavior
resolve.tsconfigPaths: trueshould apply to both build and test environments, removing the need forvite-tsconfig-paths.Actual behavior
Path aliases only resolve during build/dev. Tests fail with unresolved import errors.
Environment
Written by Claude