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
- Clone this repository on a Windows machine to a secondary drive (e.g.,
D:\.Data\vite-symlink-windows-bug).
- 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
- Open your terminal and navigate to the project via the symlinked path:
cd C:\D-Data\vite-symlink-windows-bug
- Run
npm install
- Run
npm run test
- Get the error:
Error: Cannot find module '/vitest.setup.js'.
- (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
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 toD:\.Data\...).When updating Vite from
8.1.5to8.2.0/1, running Vitest fails immediately withError: Cannot find module '/vitest.setup.js'.I believe that the path resolution for
setupFilesgets stripped down to the absolute root of the C: drive when resolving across the symlinked drives.Rolling Vite back to
8.1.5completely resolves the issue without any configuration changes.I strongly suspect this regression was introduced in
v8.2.0-beta.0by 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 orpreserveSymlinks: truewhen Vitest attempts to load the virtual module.Reproduction
https://github.com/ELowry/Vite-Symlink-Issue-Test-Repo
Steps to reproduce
D:\.Data\vite-symlink-windows-bug).mklink /J C:\D-Data\vite-symlink-windows-bug D:\.Data\vite-symlink-windows-bugcd C:\D-Data\vite-symlink-windows-bugnpm installnpm run testError: Cannot find module '/vitest.setup.js'.8.1.5and 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.1Used Package Manager
npm
Logs
Click to expand!
Validations