vitest-dev/vitest · error · TypeError
Test worker should expose "runTests" method. Received
Error message
Test worker should expose "runTests" method. Received "${typeof worker.runTests}". What it means
At worker startup Vitest selects 'runTests' or 'collectTests' on the resolved worker object based on the run method, then asserts the method exists and is a function before calling it. If the worker module does not expose that method this TypeError is thrown, reporting the actual typeof of worker.runTests.
Solutions
- Rebuild Vitest packages (pnpm build / pnpm dev) so the worker entry is current.
- Ensure all @vitest/* and vitest packages share the same version (dedupe dependencies).
- Clear node_modules/.vite and the vitest cache, then reinstall.
- If using a custom worker, make sure it re-exports runTests and collectTests from the Vitest runtime.
Example fix
// before: stale worker bundle missing runTests // (no code change; rebuild) // after: rebuild so the export exists // $ pnpm build
Defensive patterns
Strategy: type-guard
Type guard
function isWorkerCallable(worker, method) {
const name = method === 'collect' ? 'collectTests' : 'runTests'
return typeof worker?.[name] === 'function'
} Prevention
- Keep all @vitest/* packages on the same version.
- Rebuild (pnpm build) after changing runner/runtime sources.
- Clear caches and node_modules/.vite when switching branches.
When it happens
Trigger: The worker entry module (the Vitest runtime) is loaded but does not export a function named runTests (for run) or collectTests (for collect). This happens when the worker code is a stale/corrupt build, a custom worker shim is used, or the wrong entry file is loaded due to a version mismatch between vitest core and the runner package.
Common situations: Partial/failed `pnpm build` in the monorepo leaving an outdated worker bundle, mixing Vitest package versions (e.g. @vitest/runner newer than vitest), or a third-party integration that replaces the worker entry.
Related errors
- Failed to load . Default export is missing.
- Errors occurred while running tests. For more information…
- Failed to load custom "defines
- process.exit unexpectedly called with
- process.exit unexpectedly called with
AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11).
Data as JSON: /api/errors/660b117215ef0e8f.
Report an issue: GitHub.
Appendix: source
Thrown at packages/vitest/src/runtime/worker.ts:60
fetch: 0,
},
rpc,
onCancel,
onCleanup: listeners.onCleanup,
providedContext: ctx.providedContext,
onFilterStackTrace(stack) {
return createStackString(parseStacktrace(stack))
},
metaEnv: ctx.metaEnv,
getterTracker: ctx.config.benchmark.enabled && !ctx.config.benchmark.suppressExportGetterWarnings
? new GetterTracker()
: undefined,
} satisfies WorkerGlobalState
const methodName = method === 'collect' ? 'collectTests' : 'runTests'
if (!worker[methodName] || typeof worker[methodName] !== 'function') {
throw new TypeError(
`Test worker should expose "runTests" method. Received "${typeof worker.runTests}".`,
)
}
await worker[methodName](state, traces)
}
finally {
await rpcDone().catch(() => {})
await Promise.all(cleanups.map(fn => fn())).catch(() => {})
}
}
export function run(ctx: ContextRPC, worker: VitestWorker, traces: Traces): Promise<void> {
return execute('run', ctx, worker, traces)
}
export function collect(ctx: ContextRPC, worker: VitestWorker, traces: Traces): Promise<void> {
return execute('collect', ctx, worker, traces)View on GitHub (pinned to 1fa9837ec2)