ReferenceError: exports is not defined in ES module scope
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- bun, node.js, typescript, vite, vscode
- Domain
- devtools, testing-qa
Research direction
Reproduce the failure in a Bun workspace using the provided vitest.config.ts, package.json, and tsconfig settings. Start with the generated .vite-temp/vitest.config.js and the Vite loadConfigFromBundledFile path shown in the stack trace; done means the VS Code extension loads the tests without the ES module ReferenceError.
Written by the indexing model from the issue text.
Description
Describe the bug
Vitest vscode extension gives this error when it loads the tests in a workspace. I have set up all my package types to module, so it should not error about this.
ReferenceError: exports is not defined in ES module scope
Expected behavior
It should not error for exports usage. I am not using commonjs
Reproduction
Open Vitest in a bun workspace and add configurations via vitest.config.ts for one of the packages.
import solid from "vite-plugin-solid";
import { defineConfig } from "vitest/config";
export default defineConfig({
plugins: [solid()],
resolve: {
conditions: ["development", "browser"],
},
test: {
environment: "happy-dom",
globals: true,
include: ["src/**/__tests__/**/*.test.{ts,tsx}"],
},
});
My vite version is 7.3.1
Here's package.json:
{
"name": "test-workspace",
"private": true,
"main": "src/index.ts",
"type": "module",
"dependencies": {
"solid-js": "^1.9.11"
},
"devDependencies": {
"@solidjs/testing-library": "^0.8.10",
"@testing-library/user-event": "^14.6.1",
"@testing-library/dom": "^10.4.1",
"@testing-library/jest-dom": "^6.9.1",
"happy-dom": "^20.7.0",
"vite": "^7.3.1",
"vite-plugin-solid": "^2.11.10",
"vitest": "^4.0.18"
}
}
and tsconfig (merged from extends for easier understanding
{
"extends": "./node_modules/@tsconfig/bases/strictest.tsconfig.json",
"compilerOptions": {
"strictBuiltinIteratorReturn": false,
"strictPropertyInitialization": false,
"forceConsistentCasingInFileNames": true,
"target": "es2022",
"module": "esnext",
"moduleResolution": "bundler",
"lib": ["es2022"],
"noEmit": true,
"preserveWatchOutput": true,
"allowImportingTsExtensions": true,
"esModuleInterop": true,
"preserveSymlinks": true,
"declaration": true,
"sourceMap": true,
"incremental": true,
"allowJs": true,
"esModuleInterop": true,
"jsx": "preserve",
"jsxImportSource": "solid-js",
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"types": ["vite/client"],
"moduleResolution": "bundler",
"skipLibCheck": true,
"sourceMap": true,
"strict": true
},
"exclude": ["node_modules", "dist"]
}
Output
Error: Vitest failed to start:
ReferenceError: exports is not defined in ES module scope
at file:///Users/amin/work/test/packages/auth/node_modules/.vite-temp/vitest.config.js.timestamp-1775796412003-477f52e87ef0f.mjs:9:23
at ModuleJob.run (node:internal/modules/esm/module_job:345:25)
at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:665:26)
at async loadConfigFromBundledFile (file:///Users/amin/work/test/node_modules/.bun/[email protected]+31d0b22d5eb96c53/node_modules/vite/dist/node/chunks/config.js:35909:12)
at async bundleAndLoadConfigFile (file:///Users/amin/work/test/node_modules/.bun/[email protected]+31d0b22d5eb96c53/node_modules/vite/dist/node/chunks/config.js:35797:17)
at async loadConfigFromFile (file:///Users/amin/work/test/node_modules/.bun/[email protected]+31d0b22d5eb96c53/node_modules/vite/dist/node/chunks/config.js:35764:42)
at async resolveConfig (file:///Users/amin/work/test/node_modules/.bun/[email protected]+31d0b22d5eb96c53/node_modules/vite/dist/node/chunks/config.js:35413:22)
at async _createServer (file:///Users/amin/work/test/node_modules/.bun/[email protected]+31d0b22d5eb96c53/node_modules/vite/dist/node/chunks/config.js:25362:67)
at async createViteServer (file:///Users/amin/work/test/node_modules/.bun/[email protected]+b66a349cc098673f/node_modules/vitest/dist/chunks/cli-api.Bxr1Nn49.js:8820:17)
at async Module.createVitest (file:///Users/amin/work/test/node_modules/.bun/[email protected]+b66a349cc098673f/node_modules/vitest/dist/chunks/cli-api.Bxr1Nn49.js:14161:18)
at e.u (/Users/amin/.vscode/extensions/vitest.explorer-1.50.1/dist/extension.js:1:58873)
at e.emit (node:events:519:28)
at e.o.t.exports.ae (/Users/amin/.vscode/extensions/vitest.explorer-1.50.1/dist/wrapper-Br94zcvg.js:1:38577)
at e.o.t.exports.emit (node:events:519:28)
at e.o.t.exports.dataMessage (/Users/amin/.vscode/extensions/vitest.explorer-1.50.1/dist/wrapper-Br94zcvg.js:1:16501)
at e.o.t.exports.getData (/Users/amin/.vscode/extensions/vitest.explorer-1.50.1/dist/wrapper-Br94zcvg.js:1:15398)
at e.o.t.exports.startLoop (/Users/amin/.vscode/extensions/vitest.explorer-1.50.1/dist/wrapper-Br94zcvg.js:1:12110)
at e.o.t.exports._write (/Users/amin/.vscode/extensions/vitest.explorer-1.50.1/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 (/Users/amin/.vscode/extensions/vitest.explorer-1.50.1/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.1
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.
- Dominant language
- TypeScript
- Stars
- 931
- Forks
- 124
- Avg merge
- 18h 28m
- Merged PRs (30d)
- 4
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
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.
More from vitest-dev/vscode
-
pending triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
vitest-dev/vscode#776 · 1 reaction ·
-
p3-minor-bug
Difficulty 3/5 1-2 days Newbie friendliness 65/100
vitest-dev/vscode#823 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 52/100
vitest-dev/vscode#822 ·
-
enhancement: pending triage
Difficulty 3/5 1-2 days Newbie friendliness 68/100
vitest-dev/vscode#821 ·
-
pending triage
Difficulty 3/5 1-2 days Newbie friendliness 70/100
vitest-dev/vscode#812 ·
All issues in vitest-dev/vscode
Similar issues
-
ai-driven-qa bug claude Minor
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
linagora/twake-contacts-frontend#241 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
ui(ListToolbar): search takes the full row on a phone instead of sharing it with the result countOpen
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
Maintainers usually reply within 1 day
-
priority:high
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
ahmedkhaleel2004/gitdiagram#228 ·