vitest-dev/vitest · error · Error
The VM environment was not defined in the Vite config. This
Error message
The VM environment was not defined in the Vite config. This is a bug in Vitest. Please, open a new issue with reproduction.
What it means
Internal assertion in the transform RPC method: it routes raw transforms through the reserved __vitest_vm__ Vite environment, which Vitest registers automatically for in-process module transformation. If that environment is absent, the framework's own setup is broken — explicitly flagged as a bug to report, not a user config issue.
Source
Thrown at packages/vitest/src/node/pools/rpc.ts:279
return {
file: cleanUrl(resolved.id),
url: normalizeResolvedIdToUrl(environment, resolved.id),
id: resolved.id,
}
},
snapshotSaved(snapshot) {
vitest.snapshot.add(snapshot)
},
resolveSnapshotPath(testPath: string) {
return vitest.snapshot.resolvePath<ResolveSnapshotPathHandlerContext>(testPath, {
config: project.serializedConfig,
})
},
async transform(id) {
const environment = project.vite.environments.__vitest_vm__
if (!environment) {
throw new Error(`The VM environment was not defined in the Vite config. This is a bug in Vitest. Please, open a new issue with reproduction.`)
}
const url = normalizeResolvedIdToUrl(environment, fileURLToPath(id))
const result = await environment.transformRequest(url).catch(handleRollupError)
return { code: result?.code }
},
async onQueued(file) {
if (methodsOptions.collect) {
vitest.state.collectFiles(project, [file])
}
else {
await vitest._testRun.enqueued(project, file)
}
},
async onCollected(files) {
if (methodsOptions.collect) {
vitest.state.collectFiles(project, files)
}View on GitHub (pinned to d568f8ce37)
Solutions
- Report as a Vitest bug with reproduction.
- Ensure you are using the standard Vitest entry (vitest/node) and not bypassing its Vite plugin.
- Check Vitest and Vite version compatibility and upgrade/downgrade to a matched pair.
- Remove custom Vite plugins that mutate server.environments to isolate the cause.
Defensive patterns
Strategy: try-catch
Try / catch
try {
await vitest.start()
} catch (e) {
if (e.message.includes('The VM environment was not defined in the Vite config')) {
console.error('Vitest internal: __vitest_vm__ environment missing. Report as a bug.')
}
throw e
} Prevention
- Use the standard vitest/node entry so the Vitest Vite plugin registers __vitest_vm__.
- Keep Vitest and Vite versions compatible.
- Avoid custom Vite plugins that mutate server.environments.
When it happens
Trigger: rpc.transform is called and project.vite.environments.__vitest_vm__ is undefined, at packages/vitest/src/node/pools/rpc.ts:277-279. The __vitest_vm__ environment is created by Vitest's Vite plugin; its absence means the plugin did not register correctly.
Common situations: Vitest Vite plugin not loaded (custom server setup that bypasses the plugin); a severe Vite/Vitest version incompatibility; a plugin that clears environments; an experimental/custom Vitest entrypoint that skips plugin registration.
Related errors
- Cannot find the environment. This is a bug in Vitest.
- The browser server was not initialized${project.name ? ` for
- Orchestrator not found for session ${sessionId}. This is a b
- Unexpected empty queue
- Cannot set concurrency id because there are no valid free id
AI-assisted analysis of vitest-dev/vitest@d568f8ce37 (2026-08-03).
Data as JSON: /data/errors/65240462fc7baf5f.json.
Report an issue: GitHub.