vitest-dev / vitest-dev/vscode
Monorepo shared tools package TypeScript config file
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 924
- Forks
- 122
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 6
Description
Describe the bug
I found a bug in my monorepo where the extension failed discover tests when a vitest.config.ts imports a shared config helper through a workspace package export like:
import { createStandardVitestConfig } from '@org/common-tools-package/vitest/setup';
It turns out the extension was throwing an error:
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for .../packages/common-tools-package/src/vitest/setup.ts
In a terminal I can run vitest and it resolves and loads the shared package's import to the setup.ts file.
Expected behavior
Extension shows tests (w/o logged errors) for a monorepo package that imports a shared config from a common package.
Reproduction
Example Repo:
repo-root/
├─ package.json
└─ packages/
├─ package-a/
│ ├─ package.json
│ ├─ vitest.config.ts
│ └─ src/
│ └─ example.test.ts
└─ common-tools-package/
├─ package.json
└─ src/
└─ vitest/
├─ setup.ts
└─ vitest-config.ts
packages/common-tools-package/package.json:
{
"name": "@org/common-tools-package",
"type": "module",
"exports": {
"./vitest/setup": {
"types": "./src/vitest/setup.ts",
"import": "./src/vitest/setup.ts",
"require": "./src/vitest/setup.ts",
"default": "./src/vitest/setup.ts"
}
}
}
Note that if I don't use the @org/common-tools prefix and use a direct-on-disk path import like: import { createStandardVitestConfig } from '../common-tools-package/src/vitest/setup.ts' the extension can load that shared setup.ts and I can execute tests in my IDE.
Output
[INFO 2:23:41 PM] [API] Running Vitest v4.1.2 (example/vite.config.ts) with "/home/soconnor/.nvm/versions/node/v22.14.0/bin/node /home/soconnor/.vscode/extensions/vitest.explorer-1.50.4/dist/worker.js"
[2:23:41 PM] [VSCODE] Flushing 1 changed items
[Error 2:23:41 PM] There were errors during config load.
[Error 2:23:41 PM] [Error Error] Vitest failed to start:
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /home/soconnor/dev/package-a/client/packages/tools/src/vitest/setup.ts
at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:219:9)
at defaultGetFormat (node:internal/modules/esm/get_format:245:36)
at defaultLoad (node:internal/modules/esm/load:120:22)
at async ModuleLoader.loadAndTranslate (node:internal/modules/esm/loader:514:32)
Error: Vitest failed to start:
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /home/soconnor/dev/package-a/client/packages/tools/src/vitest/setup.ts
at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:219:9)
at defaultGetFormat (node:internal/modules/esm/get_format:245:36)
at defaultLoad (node:internal/modules/esm/load:120:22)
at async ModuleLoader.loadAndTranslate (node:internal/modules/esm/loader:514:32)
at e.u (/home/soconnor/.vscode/extensions/vitest.explorer-1.50.4/dist/extension.js:1:59239)
at e.emit (node:events:519:28)
at e.o.t.exports.ae (/home/soconnor/.vscode/extensions/vitest.explorer-1.50.4/dist/wrapper-Br94zcvg.js:1:38577)
at e.o.t.exports.emit (node:events:519:28)
at e.o.t.exports.dataMessage (/home/soconnor/.vscode/extensions/vitest.explorer-1.50.4/dist/wrapper-Br94zcvg.js:1:16501)
at e.o.t.exports.getData (/home/soconnor/.vscode/extensions/vitest.explorer-1.50.4/dist/wrapper-Br94zcvg.js:1:15398)
at e.o.t.exports.startLoop (/home/soconnor/.vscode/extensions/vitest.explorer-1.50.4/dist/wrapper-Br94zcvg.js:1:12110)
at e.o.t.exports._write (/home/soconnor/.vscode/extensions/vitest.explorer-1.50.4/dist/wrapper-Br94zcvg.js:1:11402)
at writeOrBuffer (node:internal/streams/writable:572:12)
at _write (node:internal/streams/writable:501:10)
at Writable.write (node:internal/streams/writable:510:10)
at Socket.Z (/home/soconnor/.vscode/extensions/vitest.explorer-1.50.4/dist/wrapper-Br94zcvg.js:1:39601)
at Socket.emit (node:events:519:28)
at addChunk (node:internal/streams/readable:561:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:512:3)
at Readable.push (node:internal/streams/readable:392:5)
at TCP.onStreamRead (node:internal/stream_base_commons:189:23)
at TCP.callbackTrampoline (node:internal/async_hooks:130:17)
Extension Version
1.50.4
Vitest Version
4.1.2
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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the failure with packages/package-a/vitest.config.ts importing packages/common-tools-package/src/vitest/setup.ts through the package.json exports. Compare the extension's behavior with terminal Vitest and inspect the config-loading path around the worker.js entry point. Done means the extension discovers the tests without logged config-load errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript, vscode
- Domain
- developer-experience, testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100