vitest-dev/vitest · critical · Error
Worker state is not found. This is an issue with Vitest. Ple
Error message
Worker state is not found. This is an issue with Vitest. Please, open an issue.
What it means
Thrown by `getWorkerState` at utils.ts:124-126 when `window.__vitest_worker__` is unset. The browser tester sets this global in state.ts:52 during boot; if it's missing, the code is running in a context that did not load the tester bootstrap (e.g. the top-level UI window, a popup, or before injection completed).
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 d568f8ce37)
Solutions
- Only call worker-state-dependent APIs from within the tester iframe loaded by Vitest.
- Verify the tester entry was loaded: `if (window.__vitest_worker__) { ... }` before calling.
- Restart the browser runner; if the bootstrap injection fails it's a Vitest/setup issue.
Example fix
// before
const state = getWorkerState() // throws in non-tester context
// after
import { getBrowserState } from '@vitest/browser/client'
if (getBrowserState() && (window as any).__vitest_worker__) {
const state = getWorkerState()
} Defensive patterns
Strategy: validation
Validate before calling
if (!(window as any).__vitest_worker__) {
throw new Error('not running inside the Vitest tester iframe')
} Type guard
function hasWorkerState(w: Window = window): boolean {
return !!(w as any).__vitest_worker__
} Prevention
- Only call worker-state APIs from the tester iframe runtime.
- Guard with window.__vitest_worker__ before invoking.
- Restart the browser runner if injection appears to have failed.
When it happens
Trigger: Calling `getWorkerState()` from the Vitest UI top frame, from a script loaded before the tester bootstrap, or from a context where the injection at esm-client-injector.js failed. Also from a manually opened browser tab pointed at the tester URL.
Common situations: Custom scripts loaded into the browser that aren't part of the test runtime. Misconfigured injection (e.g. `globalThisAccessor` tampering). Opening the iframe URL in a new tab to 'debug'.
Related errors
- Not called in the browser
- Data was not properly initialized. This is a bug in Vitest.
- 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/190b1c4f631c0c3c.json.
Report an issue: GitHub.