vitest-dev/vitest · critical · 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` at tester.ts:228-229 when `preparedData` is undefined — i.e. `executeTests('run'|'collect', specs)` was called before `prepareTestEnvironment` resolved and assigned `preparedData`. The browser tester expects preparation (runner/state assembly) to complete before any test execution message arrives; reaching this branch means the lifecycle ordering is broken.
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 d568f8ce37)
Solutions
- Ensure you're running matching versions of `vitest` and `@vitest/browser` across the workspace (run `pnpm why vitest`).
- Restart the browser pool / Vitest process — transient races after reload often clear.
- If reproducible, open a Vitest issue with the reproduction as the message requests.
Example fix
// no user code fix — this is an internal lifecycle violation // verify version alignment and restart; report if persistent
Defensive patterns
Strategy: retry
Try / catch
try {
// normal test run
} catch (err) {
if (err instanceof Error && err.message.includes('Data was not properly initialized')) {
// restart the browser runner / vitest process; this is an internal lifecycle race
throw err
}
throw err
} Prevention
- Keep vitest and @vitest/browser versions in lockstep across the workspace.
- Avoid manually orchestrating the tester entry; let Vitest drive the iframe lifecycle.
- Restart the runner on transient races; report persistent repros upstream.
When it happens
Trigger: A race where the runner receives a `collect`/`run` message before the prepare step finishes. HMR or a reload that resets `preparedData` (it's a module-level `let`) while a queued execution message fires. Manual invocation of the tester entry that skips preparation.
Common situations: This is flagged as a Vitest bug in the message itself. Real-world causes are usually version mismatches between `@vitest/browser` client and server, a broken iframe reload, or a custom orchestrator that drives the tester entry directly.
Related errors
- Worker state is not found. This is an issue with Vitest. Ple
- Not called in the browser
- Cannot find iframe element. This is a bug in Vitest. Please,
- Page "${sessionId}" not found in ${this.browserName} browser
- [vitest] The provider was closed.
AI-assisted analysis of vitest-dev/vitest@d568f8ce37 (2026-08-03).
Data as JSON: /data/errors/3c7dbbcdeac650bc.json.
Report an issue: GitHub.