{"record":{"id":"66f94e0bf3981c3f","repo":"vitejs/vite","slug":"cannot-send-non-custom-events-from-the-server-to-t","errorCode":null,"errorMessage":"Cannot send non-custom events from the server to the client.","messagePattern":"Cannot send non-custom events from the server to the client\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/vite/src/node/ssr/runtime/serverModuleRunner.ts","lineNumber":126,"sourceCode":"        undefined,\n        hmrClient,\n      )\n      onMessage({ type: 'connected' })\n      handler = onMessage\n    },\n    disconnect() {\n      if (handler) {\n        options.channel.api!.outsideEmitter.off('send', handler)\n      }\n      options.channel.api!.innerEmitter.emit(\n        'vite:client:disconnect',\n        undefined,\n        hmrClient,\n      )\n    },\n    send(payload) {\n      if (payload.type !== 'custom') {\n        throw new Error(\n          'Cannot send non-custom events from the server to the client.',\n        )\n      }\n      options.channel.api!.innerEmitter.emit(\n        payload.event,\n        payload.data,\n        hmrClient,\n      )\n    },\n  }\n}\n\n/**\n * Create an instance of the Vite SSR runtime that support HMR.\n * @experimental\n */\nexport function createServerModuleRunner(\n  environment: DevEnvironment,","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/vitejs/vite/blob/b4d66fee14d970f45b8a6f3d7d6aee73ca9b88ab/packages/vite/src/node/ssr/runtime/serverModuleRunner.ts#L108-L144","documentation":"Thrown by the server module runner transport's send() (server -> client direction) when the payload type is not 'custom'. The runner transport only forwards custom events from the dev server to the SSR module runner; built-in HMR messages take a different path.","triggerScenarios":"Server-side code (plugin, framework SSR integration) calling transport.send(payload) with a payload whose type is not 'custom'. The guard is at serverModuleRunner.ts:125.","commonSituations":"A plugin trying to broadcast an 'update'/'connected' payload to the SSR runner through the module-runner transport instead of the regular HMR channel. Misuse of the transport's send for built-in HMR orchestration.","solutions":["Only send custom events via this transport: send({ type: 'custom', event, data }).","Use environment.hot.send(...) or the regular HMR channel for built-in payload types.","If you only need RPC, prefer transport.invoke(...) which is wrapped as a custom vite:invoke event."],"exampleFix":"// before\ntransport.send({ type: 'update', updates }) // throws\n// after\ntransport.send({ type: 'custom', event: 'my-event', data: updates })","handlingStrategy":"validation","validationCode":"// only send custom payloads via the runner transport\ntransport.send({ type: 'custom', event, data })","typeGuard":"function isCustomPayload(p: HotPayload): boolean {\n  return p.type === 'custom'\n}","tryCatchPattern":null,"preventionTips":["Use the regular HMR channel for built-in payload types.","Reserve the module-runner transport send() for custom events and RPC."],"tags":["ssr","module-runner","hmr","transport"],"backgroundTag":null,"analyzedSha":"b4d66fee14d970f45b8a6f3d7d6aee73ca9b88ab","analyzedAt":"2026-08-11T11:49:19.515Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}