Skip to content

resolve.tsconfigPaths: true not applied in test environment (Vite 8) #10054

@ap-justin

Description

@ap-justin

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions