Skip to content

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

Closed

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

Activity

  1. github-actions commented on Apr 3, 2026

    @github-actions

    Hello @ap-justin. Please provide a minimal reproduction using a GitHub repository or StackBlitz (you can also use examples). Issues marked with needs reproduction will be closed if they have no activity within 3 days.

  2. hi-ogawa commented on Apr 3, 2026

    @hi-ogawa
    Collaborator

    Can you also prepare full reproduction code?

  3. MdSadiqMd commented on Apr 3, 2026

    @MdSadiqMd
    Contributor

    Hey @ap-justin are you working on this issue?
    If not @hi-ogawa can i work on this?

  4. AriPerkkio commented on Apr 3, 2026

    @AriPerkkio
    Member
  5. MdSadiqMd commented on Apr 4, 2026

    @MdSadiqMd
    Contributor

    Here is a reproduction: https://stackblitz.com/edit/vitest-dev-vitest-ukbynmwb

    Expected behavior:

    • When running npm run test:run -- test/tsconfig-paths.test.ts with plugins: [tsconfigPaths()] commented out in vite.config.ts, the test fails.
    • When running the same command with plugins: [tsconfigPaths()] enabled, all tests pass

    If this looks good, could you assign this issue to me so I can work on it?

    cc: @AriPerkkio

  6. AriPerkkio commented on Apr 5, 2026

    @AriPerkkio
    Member

    Repro looks good to me.

    We don't assign issues, feel free to work on it.

  7. hi-ogawa commented on Apr 6, 2026

    @hi-ogawa
    Collaborator

    There is/was # alias issue in Vite 8 vitejs/vite#22038 Could be relevant.

  8. Bertie690 commented on Apr 6, 2026

    @Bertie690
    Contributor
    Image Image

    Just going into the StackBlitz reproduction and changing the alias name a bunch, I'm 80% sure it's not related to what the actual makeup of the import alias is.

  9. MdSadiqMd commented on Apr 8, 2026

    @MdSadiqMd
    Contributor

    @AriPerkkio
    There is a check failing in the PR pipeline [CI / Browsers: node-24, windows-latest (pull_request)]. This does not seem to be caused by my PR, I think it’s a separate issue. Could you please take a look and review my PR?

  10. hi-ogawa commented on Apr 8, 2026

    @hi-ogawa
    Collaborator

    @MdSadiqMd The reproduction your provided here #10054 (comment) is passing for me locally. Can you check it fails on latest Vite?

  11. MdSadiqMd commented on Apr 8, 2026

    @MdSadiqMd
    Contributor

    Yes, the issue isn’t related to the latest Vite version (vite@8.0.7), it’s a problem with the version specified in the issue description, which is vite@8.0.0

  12. hi-ogawa commented on Apr 8, 2026

    @hi-ogawa
    Collaborator

    Closing since this appears to be an upstream issue and fixed on latest Vite.

  13. locked and limited conversation to collaborators on Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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