{"id":"3c7dbbcdeac650bc","repo":"vitest-dev/vitest","slug":"data-was-not-properly-initialized-this-is-a-bug-i","errorCode":null,"errorMessage":"Data was not properly initialized. This is a bug in Vitest. Please, open a new issue with reproduction.","messagePattern":"Data was not properly initialized\\. This is a bug in Vitest\\. Please, open a new issue with reproduction\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/browser/src/client/tester/tester.ts","lineNumber":229,"sourceCode":"    })\n  }\n\n  state.durations.prepare = performance.now() - options.startTime\n\n  return {\n    runner,\n    config,\n    state,\n  }\n}\n\nlet preparedData:\n  | Awaited<ReturnType<typeof prepareTestEnvironment>>\n  | undefined\n\nasync function executeTests(method: 'run' | 'collect', specifications: FileSpecification[]) {\n  if (!preparedData) {\n    throw new Error(`Data was not properly initialized. This is a bug in Vitest. Please, open a new issue with reproduction.`)\n  }\n\n  debug?.('runner resolved successfully')\n\n  const { runner, state } = preparedData\n\n  state.ctx.files = specifications\n  runner.setMethod(method)\n\n  const version = url.searchParams.get('browserv') || ''\n  specifications.forEach(({ filepath }) => {\n    const currentVersion = browserHashMap.get(filepath)\n    if (!currentVersion || currentVersion[1] !== version) {\n      browserHashMap.set(filepath, version)\n    }\n  })\n\n  for (const file of specifications) {","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/browser/src/client/tester/tester.ts#L211-L247","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// no user code fix — this is an internal lifecycle violation\n// verify version alignment and restart; report if persistent","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  // normal test run\n} catch (err) {\n  if (err instanceof Error && err.message.includes('Data was not properly initialized')) {\n    // restart the browser runner / vitest process; this is an internal lifecycle race\n    throw err\n  }\n  throw err\n}","preventionTips":["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."],"tags":["browser","tester","lifecycle","vitest-bug","internal-api"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}