-
-
Notifications
You must be signed in to change notification settings - Fork 111
Description
Describe the bug
When using a Vitest workspace configuration (vitest.workspace.ts) without a root vitest.config.ts file, the workspace API's getFiles() method returns test files from all packages in the workspace, including packages that have their own vitest.config.ts files. This causes test files to be incorrectly associated with the workspace API instead of their respective package APIs.
This leads to alias resolution failures - when test files use path aliases (e.g., import { something } from '#/somewhere'), they fail to resolve because the files are being processed by the workspace API context instead of their package-specific API context, which has the correct path alias configuration.
The issue occurs because:
- When there's no root
vitest.config.ts, Vitest doesn't report any configs invitest.configsfor the workspace API - The
usedConfigsset remains empty after workspace APIs are created - Package configs are correctly filtered out (they're in
usedConfigs), but the workspace API still returns files from those packages - This leads to duplicate file associations and incorrect API routing
Workaround: Adding a root vitest.config.ts that excludes everything (exclude: ['**']) fixes the issue, but this shouldn't be necessary.
Reproduction
-
Create a monorepo workspace with the following structure:
workspace-root/ ├── vitest.workspace.ts └── packages/ ├── package-a/ │ ├── vitest.config.ts │ └── test/ │ └── test.spec.ts └── package-b/ ├── vitest.config.ts └── test/ └── test.spec.ts -
Configure
vitest.workspace.tsto include the package configs:export default [ './packages/package-a/vitest.config.ts', './packages/package-b/vitest.config.ts', ]
-
Do NOT create a root
vitest.config.tsfile -
Open the workspace in VS Code with the Vitest extension installed
-
Observe that:
- The workspace API's
getFiles()returns files from bothpackage-aandpackage-b - Package APIs also return their own files
- Test files are incorrectly associated with the workspace API instead of their package APIs
- Path aliases fail to resolve - imports like
import { something } from '#/somewhere'fail with errors such as:Error: Failed to resolve import "#/somewhere" from "packages/package-a/test/test.spec.ts". Does the file exist?
- The workspace API's
Output
With vitest.config.ts at workspace root that excludes all files (it works)
[INFO 10:33:48] [API] Collecting tests: packages/debug/test/unit/log/filePathResolvers.test.ts
[10:33:50] Disposing test runner
[10:33:50] Ending test run <none>
[10:33:50] Disposing test runner
[10:33:50] Ending test run <none>
[10:33:50] Disposing test runner
[10:33:50] Ending test run <none>
[10:33:50] Disposing test runner
[10:33:50] Ending test run <none>
[INFO 10:33:50] [API] Vitest process 89198 closed successfully
[INFO 10:33:50] [API] Vitest process 89238 closed successfully
[INFO 10:33:50] [API] Vitest process 89249 closed successfully
[INFO 10:33:50] [API] Vitest process 89252 closed successfully
[Error 10:33:50] Failed to close server
[10:33:50] [API] Vitest WebSocket connection closed, cannot call RPC anymore.
[Error 10:33:50] Failed to close server
[10:33:50] [API] Vitest WebSocket connection closed, cannot call RPC anymore.
[INFO 10:33:50] [API DEBUG] resolveVitestAPI called with:
[INFO 10:33:50] [API DEBUG] 1 workspace configs: [object Object]
[INFO 10:33:50] [API DEBUG] 4 package configs: [object Object],[object Object],[object Object],[object Object]
[INFO 10:33:50] [API] Resolving workspace configs: vitest.workspace.ts
[INFO 10:33:50] [API] Running Vitest v4.0.16 (ts-dk/vitest.workspace.ts) with "/Users/sam/.nvm/versions/node/v24.12.0/bin/node /Users/sam/Development/vscode/dist/worker.js"
[Error 10:33:50] Failed to close server
[Error 10:33:50] Failed to close server
[10:33:50] [API] Vitest WebSocket connection closed, cannot call RPC anymore.
[10:33:50] [API] Vitest WebSocket connection closed, cannot call RPC anymore.
[INFO 10:33:51] [API DEBUG] Creating WORKSPACE API for: [object Object]
[INFO 10:33:51] [API DEBUG] WORKSPACE API added 1 configs to usedConfigs: /Users/sam/Development/am.ninja/ts-dk/vitest.config.ts
[INFO 10:33:51] [API DEBUG] Resolved 1 workspace APIs
[INFO 10:33:51] [API DEBUG] Workspace roots:
[INFO 10:33:51] [API DEBUG] Used configs after workspace APIs: /Users/sam/Development/am.ninja/ts-dk/vitest.config.ts
[INFO 10:33:51] [API] Resolving configs: debug/vitest.config.ts, workflow/vitest.config.ts, utils/vitest.config.ts
[INFO 10:33:51] [API] Running Vitest v4.0.16 (debug/vitest.config.ts) with "/Users/sam/.nvm/versions/node/v24.12.0/bin/node /Users/sam/Development/vscode/dist/worker.js"
[INFO 10:33:51] [API DEBUG] Creating PACKAGE API for: [object Object]
[INFO 10:33:51] [API DEBUG] PACKAGE API added 1 configs to usedConfigs: /Users/sam/Development/am.ninja/ts-dk/packages/debug/vitest.config.ts
[INFO 10:33:51] [API] Running Vitest v4.0.16 (workflow/vitest.config.ts) with "/Users/sam/.nvm/versions/node/v24.12.0/bin/node /Users/sam/Development/vscode/dist/worker.js"
[INFO 10:33:51] [API DEBUG] Creating PACKAGE API for: [object Object]
[INFO 10:33:51] [API DEBUG] PACKAGE API added 1 configs to usedConfigs: /Users/sam/Development/am.ninja/ts-dk/packages/workflow/vitest.config.ts
[INFO 10:33:51] [API] Running Vitest v4.0.16 (utils/vitest.config.ts) with "/Users/sam/.nvm/versions/node/v24.12.0/bin/node /Users/sam/Development/vscode/dist/worker.js"
[INFO 10:33:51] [API DEBUG] Creating PACKAGE API for: [object Object]
[INFO 10:33:51] [API DEBUG] PACKAGE API added 1 configs to usedConfigs: /Users/sam/Development/am.ninja/ts-dk/packages/utils/vitest.config.ts
[INFO 10:33:51] [API DEBUG] WORKSPACE API getFiles() returned 0 files. workspaceFile: /Users/sam/Development/am.ninja/ts-dk/vitest.workspace.ts
[INFO 10:33:51] [API DEBUG] discoverAllTestFiles called for WORKSPACE API with 0 files
[INFO 10:33:51] [API DEBUG] WORKSPACE API details: [object Object]
[INFO 10:33:51] [API] Watching vitest.workspace.ts
[INFO 10:33:51] [VSCODE] Watching ts-dk with pattern **/*
[INFO 10:33:51] [API DEBUG] PACKAGE API getFiles() returned 1 files. configFile: /Users/sam/Development/am.ninja/ts-dk/packages/debug/vitest.config.ts, cwd: /Users/sam/Development/am.ninja/ts-dk/packages/debug
[INFO 10:33:51] [API DEBUG] Files from PACKAGE API: /Users/sam/Development/am.ninja/ts-dk/packages/debug/test/unit/log/filePathResolvers.test.ts
[INFO 10:33:51] [API DEBUG] discoverAllTestFiles called for PACKAGE API with 1 files
[INFO 10:33:51] [API DEBUG] PACKAGE API details: [object Object]
[INFO 10:33:51] [API] Watching packages/debug/vitest.config.ts
[INFO 10:33:51] [API DEBUG] PACKAGE API getFiles() returned 1 files. configFile: /Users/sam/Development/am.ninja/ts-dk/packages/workflow/vitest.config.ts, cwd: /Users/sam/Development/am.ninja/ts-dk/packages/workflow
[INFO 10:33:51] [API DEBUG] Files from PACKAGE API: /Users/sam/Development/am.ninja/ts-dk/packages/workflow/test/unit/gitUtils.test.ts
[INFO 10:33:51] [API DEBUG] discoverAllTestFiles called for PACKAGE API with 1 files
[INFO 10:33:51] [API DEBUG] PACKAGE API details: [object Object]
[INFO 10:33:51] [API] Watching packages/workflow/vitest.config.ts
[INFO 10:33:51] [API DEBUG] PACKAGE API getFiles() returned 1 files. configFile: /Users/sam/Development/am.ninja/ts-dk/packages/utils/vitest.config.ts, cwd: /Users/sam/Development/am.ninja/ts-dk/packages/utils
[INFO 10:33:51] [API DEBUG] Files from PACKAGE API: /Users/sam/Development/am.ninja/ts-dk/packages/utils/test/unit/index.test.ts
[INFO 10:33:51] [API DEBUG] discoverAllTestFiles called for PACKAGE API with 1 files
[INFO 10:33:51] [API DEBUG] PACKAGE API details: [object Object]
[INFO 10:33:51] [API] Watching packages/utils/vitest.config.ts
[INFO 10:33:52] [API] Collecting tests: packages/debug/test/unit/log/filePathResolvers.test.ts
---
Without workspace root vitest.config.ts (it fails)
[10:32:29] Disposing test runner
[10:32:29] Ending test run <none>
[10:32:29] Disposing test runner
[10:32:29] Ending test run <none>
[10:32:29] Disposing test runner
[10:32:29] Ending test run <none>
[10:32:29] Disposing test runner
[10:32:29] Ending test run <none>
[INFO 10:32:29] [API] Vitest process 86213 closed successfully
[INFO 10:32:29] [API] Vitest process 86225 closed successfully
[INFO 10:32:29] [API] Vitest process 86243 closed successfully
[INFO 10:32:29] [API] Vitest process 86246 closed successfully
[Error 10:32:29] Failed to close server
[10:32:29] [API] Vitest WebSocket connection closed, cannot call RPC anymore.
[INFO 10:32:29] [API DEBUG] resolveVitestAPI called with:
[INFO 10:32:29] [API DEBUG] 1 workspace configs: [object Object]
[INFO 10:32:29] [API DEBUG] 3 package configs: [object Object],[object Object],[object Object]
[INFO 10:32:29] [API] Resolving workspace configs: vitest.workspace.ts
[INFO 10:32:29] [API] Running Vitest v4.0.16 (ts-dk/vitest.workspace.ts) with "/Users/sam/.nvm/versions/node/v24.12.0/bin/node /Users/sam/Development/vscode/dist/worker.js"
[Error 10:32:29] Failed to close server
[Error 10:32:29] Failed to close server
[Error 10:32:29] Failed to close server
[10:32:29] [API] Vitest WebSocket connection closed, cannot call RPC anymore.
[10:32:29] [API] Vitest WebSocket connection closed, cannot call RPC anymore.
[10:32:29] [API] Vitest WebSocket connection closed, cannot call RPC anymore.
[INFO 10:32:29] [API DEBUG] Creating WORKSPACE API for: [object Object]
[INFO 10:32:29] [API DEBUG] WORKSPACE API added 0 configs to usedConfigs:
[INFO 10:32:29] [API DEBUG] Resolved 1 workspace APIs
[INFO 10:32:29] [API DEBUG] Workspace roots:
[INFO 10:32:29] [API DEBUG] Used configs after workspace APIs:
[INFO 10:32:29] [API] Resolving configs: debug/vitest.config.ts, workflow/vitest.config.ts, utils/vitest.config.ts
[INFO 10:32:29] [API] Running Vitest v4.0.16 (debug/vitest.config.ts) with "/Users/sam/.nvm/versions/node/v24.12.0/bin/node /Users/sam/Development/vscode/dist/worker.js"
[INFO 10:32:30] [API DEBUG] Creating PACKAGE API for: [object Object]
[INFO 10:32:30] [API DEBUG] PACKAGE API added 1 configs to usedConfigs: /Users/sam/Development/am.ninja/ts-dk/packages/debug/vitest.config.ts
[INFO 10:32:30] [API] Running Vitest v4.0.16 (workflow/vitest.config.ts) with "/Users/sam/.nvm/versions/node/v24.12.0/bin/node /Users/sam/Development/vscode/dist/worker.js"
[INFO 10:32:30] [API DEBUG] Creating PACKAGE API for: [object Object]
[INFO 10:32:30] [API DEBUG] PACKAGE API added 1 configs to usedConfigs: /Users/sam/Development/am.ninja/ts-dk/packages/workflow/vitest.config.ts
[INFO 10:32:30] [API] Running Vitest v4.0.16 (utils/vitest.config.ts) with "/Users/sam/.nvm/versions/node/v24.12.0/bin/node /Users/sam/Development/vscode/dist/worker.js"
[INFO 10:32:30] [API DEBUG] Creating PACKAGE API for: [object Object]
[INFO 10:32:30] [API DEBUG] PACKAGE API added 1 configs to usedConfigs: /Users/sam/Development/am.ninja/ts-dk/packages/utils/vitest.config.ts
[INFO 10:32:30] [API DEBUG] WORKSPACE API getFiles() returned 3 files. workspaceFile: /Users/sam/Development/am.ninja/ts-dk/vitest.workspace.ts
[INFO 10:32:30] [API DEBUG] Files from WORKSPACE API: /Users/sam/Development/am.ninja/ts-dk/packages/utils/test/unit/index.test.ts,/Users/sam/Development/am.ninja/ts-dk/packages/workflow/test/unit/gitUtils.test.ts,/Users/sam/Development/am.ninja/ts-dk/packages/debug/test/unit/log/filePathResolvers.test.ts
[INFO 10:32:30] [API DEBUG] discoverAllTestFiles called for WORKSPACE API with 3 files
[INFO 10:32:30] [API DEBUG] WORKSPACE API details: [object Object]
[INFO 10:32:30] [API] Watching vitest.workspace.ts
[INFO 10:32:30] [VSCODE] Watching ts-dk with pattern **/*
[INFO 10:32:30] [API DEBUG] PACKAGE API getFiles() returned 1 files. configFile: /Users/sam/Development/am.ninja/ts-dk/packages/debug/vitest.config.ts, cwd: /Users/sam/Development/am.ninja/ts-dk/packages/debug
[INFO 10:32:30] [API DEBUG] Files from PACKAGE API: /Users/sam/Development/am.ninja/ts-dk/packages/debug/test/unit/log/filePathResolvers.test.ts
[INFO 10:32:30] [API DEBUG] discoverAllTestFiles called for PACKAGE API with 1 files
[INFO 10:32:30] [API DEBUG] PACKAGE API details: [object Object]
[INFO 10:32:30] [API] Watching packages/debug/vitest.config.ts
[INFO 10:32:30] [API DEBUG] PACKAGE API getFiles() returned 1 files. configFile: /Users/sam/Development/am.ninja/ts-dk/packages/workflow/vitest.config.ts, cwd: /Users/sam/Development/am.ninja/ts-dk/packages/workflow
[INFO 10:32:30] [API DEBUG] Files from PACKAGE API: /Users/sam/Development/am.ninja/ts-dk/packages/workflow/test/unit/gitUtils.test.ts
[INFO 10:32:30] [API DEBUG] discoverAllTestFiles called for PACKAGE API with 1 files
[INFO 10:32:30] [API DEBUG] PACKAGE API details: [object Object]
[INFO 10:32:30] [API] Watching packages/workflow/vitest.config.ts
[INFO 10:32:30] [API DEBUG] PACKAGE API getFiles() returned 1 files. configFile: /Users/sam/Development/am.ninja/ts-dk/packages/utils/vitest.config.ts, cwd: /Users/sam/Development/am.ninja/ts-dk/packages/utils
[INFO 10:32:30] [API DEBUG] Files from PACKAGE API: /Users/sam/Development/am.ninja/ts-dk/packages/utils/test/unit/index.test.ts
[INFO 10:32:30] [API DEBUG] discoverAllTestFiles called for PACKAGE API with 1 files
[INFO 10:32:30] [API DEBUG] PACKAGE API details: [object Object]
[INFO 10:32:30] [API] Watching packages/utils/vitest.config.ts
[INFO 10:32:30] [API] Collecting tests: packages/debug/test/unit/log/filePathResolvers.test.ts
[Error 10:32:30] Error in /Users/sam/Development/am.ninja/ts-dk/packages/debug/test/unit/log/filePathResolvers.test.ts Error: Failed to resolve import "#/log/filePathResolvers" from "packages/debug/test/unit/log/filePathResolvers.test.ts". Does the file exist?
at TransformPluginContext._formatLog (file:///Users/sam/Development/am.ninja/ts-dk/node_modules/.pnpm/vite@7.3.0_@types+node@24.10.4_jiti@2.6.1_terser@5.44.1_tsx@4.21.0_yaml@2.8.2/node_modules/vite/dist/node/chunks/config.js:28998:43)
at TransformPluginContext.error (file:///Users/sam/Development/am.ninja/ts-dk/node_modules/.pnpm/vite@7.3.0_@types+node@24.10.4_jiti@2.6.1_terser@5.44.1_tsx@4.21.0_yaml@2.8.2/node_modules/vite/dist/node/chunks/config.js:28995:14)
at normalizeUrl (file:///Users/sam/Development/am.ninja/ts-dk/node_modules/.pnpm/vite@7.3.0_@types+node@24.10.4_jiti@2.6.1_terser@5.44.1_tsx@4.21.0_yaml@2.8.2/node_modules/vite/dist/node/chunks/config.js:27118:18)
at processTicksAndRejections (node:internal/process/task_queues:103:5)
at file:///Users/sam/Development/am.ninja/ts-dk/node_modules/.pnpm/vite@7.3.0_@types+node@24.10.4_jiti@2.6.1_terser@5.44.1_tsx@4.21.0_yaml@2.8.2/node_modules/vite/dist/node/chunks/config.js:27176:32
at async Promise.all (index 4)
at TransformPluginContext.transform (file:///Users/sam/Development/am.ninja/ts-dk/node_modules/.pnpm/vite@7.3.0_@types+node@24.10.4_jiti@2.6.1_terser@5.44.1_tsx@4.21.0_yaml@2.8.2/node_modules/vite/dist/node/chunks/config.js:27144:4)
at EnvironmentPluginContainer.transform (file:///Users/sam/Development/am.ninja/ts-dk/node_modules/.pnpm/vite@7.3.0_@types+node@24.10.4_jiti@2.6.1_terser@5.44.1_tsx@4.21.0_yaml@2.8.2/node_modules/vite/dist/node/chunks/config.js:28796:14)
at loadAndTransform (file:///Users/sam/Development/am.ninja/ts-dk/node_modules/.pnpm/vite@7.3.0_@types+node@24.10.4_jiti@2.6.1_terser@5.44.1_tsx@4.21.0_yaml@2.8.2/node_modules/vite/dist/node/chunks/config.js:22669:26)Extension Version
1.36.0 commit: ff6e44d
Vitest Version
4.0.16
Validations
- Check that you are using the latest version of the extension
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.