{"record":{"id":"660b117215ef0e8f","repo":"vitest-dev/vitest","slug":"test-worker-should-expose-runtests-method-recei","errorCode":null,"errorMessage":"Test worker should expose \"runTests\" method. Received \"${typeof worker.runTests}\".","messagePattern":"Test worker should expose \"runTests\" method\\. Received \"(.+?)\"\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/runtime/worker.ts","lineNumber":60,"sourceCode":"        fetch: 0,\n      },\n      rpc,\n      onCancel,\n      onCleanup: listeners.onCleanup,\n      providedContext: ctx.providedContext,\n      onFilterStackTrace(stack) {\n        return createStackString(parseStacktrace(stack))\n      },\n      metaEnv: ctx.metaEnv,\n      getterTracker: ctx.config.benchmark.enabled && !ctx.config.benchmark.suppressExportGetterWarnings\n        ? new GetterTracker()\n        : undefined,\n    } satisfies WorkerGlobalState\n\n    const methodName = method === 'collect' ? 'collectTests' : 'runTests'\n\n    if (!worker[methodName] || typeof worker[methodName] !== 'function') {\n      throw new TypeError(\n        `Test worker should expose \"runTests\" method. Received \"${typeof worker.runTests}\".`,\n      )\n    }\n\n    await worker[methodName](state, traces)\n  }\n  finally {\n    await rpcDone().catch(() => {})\n    await Promise.all(cleanups.map(fn => fn())).catch(() => {})\n  }\n}\n\nexport function run(ctx: ContextRPC, worker: VitestWorker, traces: Traces): Promise<void> {\n  return execute('run', ctx, worker, traces)\n}\n\nexport function collect(ctx: ContextRPC, worker: VitestWorker, traces: Traces): Promise<void> {\n  return execute('collect', ctx, worker, traces)","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/vitest/src/runtime/worker.ts#L42-L78","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before: stale worker bundle missing runTests\n// (no code change; rebuild)\n\n// after: rebuild so the export exists\n// $ pnpm build","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function isWorkerCallable(worker, method) {\n  const name = method === 'collect' ? 'collectTests' : 'runTests'\n  return typeof worker?.[name] === 'function'\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["worker","version-mismatch","build","runtime"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}