vitest-dev/vitest · error · Error
Worker state is not found. This is an issue with Vitest…
Error message
Worker state is not found. This is an issue with Vitest. Please, open an issue.
What it means
Thrown by `getWorkerState` when `window.__vitest_worker__` is undefined/null. The browser tester sets this global before tests run (it holds the `WorkerGlobalState` with config, RPC, mocker, etc.). Missing it means the code is executing outside the browser tester's prepared context — e.g. in a plain page, before the tester bootstrap ran, or in Node where `window` is undefined/polyfilled.
Solutions
- Run the code only inside a Vitest browser test (the tester sets the global).
- For Node-side logic, use Node-appropriate utilities, not the browser client helpers.
- If this appears inside a browser test, it is a tester bootstrap bug — report it with a reproduction.
Defensive patterns
Strategy: validation
Validate before calling
// guard before using browser worker utilities
const g = globalThis as { __vitest_worker__?: unknown }
if (!g.__vitest_worker__) {
throw new Error('Not running inside the Vitest browser tester')
} Prevention
- Run browser-only utilities only inside browser tests.
- Do not import `@vitest/browser` client helpers in Node test files.
- Confirm the tester bootstrap has run before relying on worker state.
When it happens
Trigger: Calling `getWorkerState()` from a non-tester page, before the tester bootstrap script ran, or from Node code that imported browser-only utilities.
Common situations: Importing `@vitest/browser` client utilities in a Node test file; the tester HTML being loaded standalone; an ordering bug where the utility runs before `state.ts` assigns `window.__vitest_worker__`.
Related errors
- Data was not properly initialized. This is a bug in Vitest…
- Not called in the browser
- Browser is not initialized
- Cannot find iframe element. This is a bug in Vitest…
- Cannot take a screenshot outside of a test.
AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11).
Data as JSON: /api/errors/190b1c4f631c0c3c.
Report an issue: GitHub.
Appendix: source
Thrown at packages/browser/src/client/utils.ts:125
off: (event: string, listener: (payload: any) => void) => void
send: (method: string, params?: Record<string, unknown>) => Promise<unknown>
emit: (event: string, payload: unknown) => void
}
aria: typeof import('ivya/aria')
}
/* @__NO_SIDE_EFFECTS__ */
export function getBrowserState(): BrowserRunnerState {
// @ts-expect-error not typed global
return window.__vitest_browser_runner__
}
/* @__NO_SIDE_EFFECTS__ */
export function getWorkerState(): WorkerGlobalState {
// @ts-expect-error not typed global
const state = window.__vitest_worker__
if (!state) {
throw new Error('Worker state is not found. This is an issue with Vitest. Please, open an issue.')
}
return state
}
View on GitHub (pinned to 1fa9837ec2)