{"id":"eee85fec44bbe9f2","repo":"vitest-dev/vitest","slug":"unexpected-message-json-stringify-message-null","errorCode":null,"errorMessage":"Unexpected message ${JSON.stringify(message, null, 2)}","messagePattern":"Unexpected message (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vitest/src/node/pools/workers/typecheckWorker.ts","lineNumber":100,"sourceCode":"\n      return { type: 'testfileFinished', error, __vitest_worker_response__ }\n    }\n\n    case 'collect': {\n      runPromise = runner.collectTests(message.context.files, project)\n        .catch(error => error)\n      const error = await runPromise\n\n      return { type: 'testfileFinished', error, __vitest_worker_response__ }\n    }\n\n    case 'stop': {\n      await runPromise\n      return { type: 'stopped', __vitest_worker_response__ }\n    }\n  }\n\n  throw new Error(`Unexpected message ${JSON.stringify(message, null, 2)}`)\n}\n\nfunction createRunner(vitest: Vitest) {\n  const promisesMap = new WeakMap<TestProject, DeferPromise<void>>()\n  const rerunTriggered = new WeakSet<TestProject>()\n\n  async function onParseEnd(\n    project: TestProject,\n    { files, sourceErrors }: TypecheckResults,\n  ) {\n    const checker = project.typechecker!\n\n    const { packs, events } = checker.getTestPacksAndEvents()\n    await vitest._testRun.updated(packs, events)\n\n    if (!project.config.typecheck.ignoreSourceErrors) {\n      sourceErrors.forEach(error =>\n        vitest.state.catchError(error, 'Unhandled Source Error'),","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/vitest/src/node/pools/workers/typecheckWorker.ts#L82-L118","documentation":"Thrown by the typecheck worker's onMessage dispatcher when the incoming WorkerRequest does not match any handled type ('start','run','collect','stop'). The switch in onMessage fell through, meaning an unexpected or malformed message was delivered to the in-process typechecker worker.","triggerScenarios":"TypecheckPoolWorker.send -> onMessage receives a message whose type is not one of 'start' | 'run' | 'collect' | 'stop', or whose __vitest_worker_request__ is true but the type is unknown, reaching packages/vitest/src/node/pools/workers/typecheckWorker.ts:100.","commonSituations":"An internal protocol mismatch (Vitest runtime version != typecheck worker version); a regression adding a new message type without updating the dispatcher; experimental API misuse sending a custom request type through the typecheck pool.","solutions":["Report as a Vitest bug with reproduction, including the JSON of the unexpected message.","Ensure you are not mixing Vitest versions across a workspace (hoisted vs nested installs).","Reinstall dependencies to rule out a stale/partial build of the typecheck runtime."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await vitest.start()\n} catch (e) {\n  if (e.message.startsWith('Unexpected message')) {\n    console.error('Typecheck worker protocol mismatch. Check for mixed Vitest versions.')\n    console.error('Message:', e.message)\n  }\n  throw e\n}","preventionTips":["Avoid mixing Vitest versions across a workspace (dedupe with pnpm overrides).","Reinstall dependencies to rule out stale/partial typecheck runtime builds.","Pin compatible Vitest versions in all projects."],"tags":["typecheck","worker","internal-bug","rpc-protocol","assertion"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}