Skip to content

Regression in 8.2: Vitest setupFiles fails with "Cannot find module" across Windows drive symlinks #23197

Description

@ELowry

Describe the bug

I am running a Vitest test suite on Windows where my project directory is accessed via a symlink across different drive letters (e.g., executing in C:\D-Data\... which is symlinked to D:\.Data\...).

When updating Vite from 8.1.5 to 8.2.0/1, running Vitest fails immediately with Error: Cannot find module '/vitest.setup.js'.
I believe that the path resolution for setupFiles gets stripped down to the absolute root of the C: drive when resolving across the symlinked drives.

Rolling Vite back to 8.1.5 completely resolves the issue without any configuration changes.

I strongly suspect this regression was introduced in v8.2.0-beta.0 by PR #22832 (resolve root to real path), which may be incorrectly forcing the root to the real path (D:) and failing to respect the execution context or preserveSymlinks: true when Vitest attempts to load the virtual module.

Reproduction

https://github.com/ELowry/Vite-Symlink-Issue-Test-Repo

Steps to reproduce

  1. Clone this repository on a Windows machine to a secondary drive (e.g., D:\.Data\vite-symlink-windows-bug).
  2. Open an Administrator command prompt and create a directory junction/symlink on the primary drive pointing to it:
    mklink /J C:\D-Data\vite-symlink-windows-bug D:\.Data\vite-symlink-windows-bug
  3. Open your terminal and navigate to the project via the symlinked path:
    cd C:\D-Data\vite-symlink-windows-bug
  4. Run npm install
  5. Run npm run test
  6. Get the error: Error: Cannot find module '/vitest.setup.js'.
  7. (optional) Downgrade Vite to 8.1.5 and test again, it should work without any errors.

System Info

System:
    OS: Windows 11 10.0.26200
    CPU: (16) x64 AMD Ryzen 7 5800X 8-Core Processor
    Memory: 10.49 GB / 31.93 GB
  Binaries:
    Node: 24.16.0 - C:\nvm4w\nodejs\node.EXE
    npm: 12.0.1 - C:\nvm4w\nodejs\npm.CMD
  Browsers:
    Chrome: 150.0.7871.187
    Edge: Chromium (151.0.4129.59)
    Firefox: 153.0.1 - C:\Program Files\Mozilla Firefox\firefox.exe
    Internet Explorer: 11.0.26100.8115
  npmPackages:
    vite: ^8.2.1 => 8.2.1

Used Package Manager

npm

Logs

Click to expand!
C:\D-Data\vite-symlink-repo [main ≡ +0 ~1 -0 !]> npm run test
npm notice run vite-symlink-repro@1.0.0 test
npm notice run vitest run

 RUN  v4.1.10 D:/.Data/vite-symlink-repo

 ❯ dummy.test.js (0 test)

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Suites 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

 FAIL  dummy.test.js [ dummy.test.js ]
Error: Cannot find module '/vitest.setup.js'
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯


 Test Files  1 failed (1)
      Tests  no tests
   Start at  21:40:57
   Duration  983ms (transform 0ms, setup 0ms, import 0ms, tests 0ms, environment 810ms) 

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions