{"id":"748a7adea0420dcb","repo":"nestjs/nest","slug":"method-is-not-supported-in-grpc-mode","errorCode":null,"errorMessage":"Method is not supported in gRPC mode.","messagePattern":"Method is not supported in gRPC mode\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/microservices/client/client-grpc.ts","lineNumber":396,"sourceCode":"  }\n\n  protected publish(packet: any, callback: (packet: any) => any): any {\n    throw new Error(\n      'Method is not supported in gRPC mode. Use ClientGrpc instead (learn more in the documentation).',\n    );\n  }\n\n  protected async dispatchEvent(packet: any): Promise<any> {\n    throw new Error(\n      'Method is not supported in gRPC mode. Use ClientGrpc instead (learn more in the documentation).',\n    );\n  }\n\n  public on<EventKey extends never = never, EventCallback = any>(\n    event: EventKey,\n    callback: EventCallback,\n  ) {\n    throw new Error('Method is not supported in gRPC mode.');\n  }\n\n  public unwrap<T>(): T {\n    throw new Error('Method is not supported in gRPC mode.');\n  }\n}\n","sourceCodeStart":378,"sourceCodeEnd":403,"githubUrl":"https://github.com/nestjs/nest/blob/6ec0e2783d15290732447f304d8549b591b9749e/packages/microservices/client/client-grpc.ts#L378-L403","documentation":"`ClientGrpcProxy.on(event, callback)` throws because the connection-event-emitter API (`on('connected', ...)`) is not supported for gRPC. The signature `EventKey extends never` also makes this statically impossible to call with any real event name. Connection lifecycle is managed internally by grpc-js.","triggerScenarios":"Calling `clientGrpc.on('connected', cb)` (or any event) on a gRPC client proxy.","commonSituations":"Generic status/health reporting code that subscribes to events on every `ClientProxy`; copy-paste from another transport's connection handler.","solutions":["Remove the `on()` call for gRPC clients; rely on per-call Observables and their error callback.","Branch status-reporting code by transport type.","If you need grpc-js channel-state events, access the underlying client via `getService()` callbacks (note `unwrap()` is also unsupported)."],"exampleFix":"// before\nclient.on('connected', () => logger.log('gRPC ready'));\n// after\nconst math = client.getService<MathClient>('Math');\nmath.sum({ data: [1] }).subscribe({\n  next: r => logger.log('gRPC call ok', r),\n  error: e => logger.error('gRPC call failed', e),\n});","handlingStrategy":"type-guard","validationCode":"import { ClientGrpc } from '@nestjs/microservices';\n// gRPC clients do not support on(); subscribe to per-call Observables instead\nif (!('on' in client)) { /* skip */ }","typeGuard":"import { ClientGrpc } from '@nestjs/microservices';\nfunction isGrpcClient(c: unknown): c is ClientGrpc {\n  return typeof c === 'object' && c !== null && typeof (c as any).getService === 'function';\n}","tryCatchPattern":null,"preventionTips":["Branch status-reporting code by transport; skip `on()` for gRPC.","Handle per-call Observable errors for gRPC health signals.","Use a transport-agnostic health-check abstraction."],"tags":["grpc","microservices","events","api-misuse","nestjs"],"analyzedSha":"6ec0e2783d15290732447f304d8549b591b9749e","analyzedAt":"2026-08-03T17:42:23.673Z","schemaVersion":2}