vitest-dev/vitest · error · Error
Data was not properly initialized. This is a bug in Vitest…
Error message
Data was not properly initialized. This is a bug in Vitest. Please, open a new issue with reproduction.
What it means
Thrown by `executeTests` when the module-level `preparedData` is still undefined. `preparedData` is populated by `prepareTestEnvironment` (which builds the runner, RPC, mocker, and worker state) before `executeTests` is called. If `executeTests` runs first, the runner/state/config are missing and execution cannot proceed. The message explicitly flags this as a Vitest internal bug rather than a user error.
Solutions
- Use the standard Vitest browser tester entry point that calls `prepareTestEnvironment` before `executeTests`.
- If customizing the tester, ensure `prepareTestEnvironment` has resolved before invoking `executeTests`.
- Treat as a Vitest bug: open an issue with a minimal reproduction.
Defensive patterns
Strategy: validation
Validate before calling
// internal contract: prepareTestEnvironment must run first
if (!preparedData) {
await prepareTestEnvironment(opts)
}
await executeTests('run', specs) Prevention
- Use the standard browser tester entry point that prepares before executing.
- Do not invoke `executeTests` from custom code without preparing first.
- Report regressions as Vitest bugs with a reproduction.
When it happens
Trigger: The browser tester's bootstrap sequence is interrupted or reordered so `executeTests('run'|'collect', specs)` is called before `prepareTestEnvironment` completes; a custom entry point that calls `executeTests` directly.
Common situations: An upstream Vitest regression in the tester bootstrap; a race where the runner message arrives before environment preparation; a customized tester HTML/entry that skips `prepareTestEnvironment`.
Related errors
- Worker state is not found. This is an issue with Vitest…
- Browser is not initialized
- Cannot find iframe element. This is a bug in Vitest…
- Don't have access to the "vitest" instance yet. This is a…
- Expected DOM element to be an instance of Element, received
AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11).
Data as JSON: /api/errors/3c7dbbcdeac650bc.
Report an issue: GitHub.
Appendix: source
Thrown at packages/browser/src/client/tester/tester.ts:229
})
}
state.durations.prepare = performance.now() - options.startTime
return {
runner,
config,
state,
}
}
let preparedData:
| Awaited<ReturnType<typeof prepareTestEnvironment>>
| undefined
async function executeTests(method: 'run' | 'collect', specifications: FileSpecification[]) {
if (!preparedData) {
throw new Error(`Data was not properly initialized. This is a bug in Vitest. Please, open a new issue with reproduction.`)
}
debug?.('runner resolved successfully')
const { runner, state } = preparedData
state.ctx.files = specifications
runner.setMethod(method)
const version = url.searchParams.get('browserv') || ''
specifications.forEach(({ filepath }) => {
const currentVersion = browserHashMap.get(filepath)
if (!currentVersion || currentVersion[1] !== version) {
browserHashMap.set(filepath, version)
}
})
for (const file of specifications) {View on GitHub (pinned to 1fa9837ec2)