nestjs/nest · error · Error
Method is not supported in gRPC mode.
Error message
Method is not supported in gRPC mode.
What it means
`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.
Source
Thrown at packages/microservices/client/client-grpc.ts:396
}
protected publish(packet: any, callback: (packet: any) => any): any {
throw new Error(
'Method is not supported in gRPC mode. Use ClientGrpc instead (learn more in the documentation).',
);
}
protected async dispatchEvent(packet: any): Promise<any> {
throw new Error(
'Method is not supported in gRPC mode. Use ClientGrpc instead (learn more in the documentation).',
);
}
public on<EventKey extends never = never, EventCallback = any>(
event: EventKey,
callback: EventCallback,
) {
throw new Error('Method is not supported in gRPC mode.');
}
public unwrap<T>(): T {
throw new Error('Method is not supported in gRPC mode.');
}
}
View on GitHub (pinned to 6ec0e2783d)
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).
Example fix
// before
client.on('connected', () => logger.log('gRPC ready'));
// after
const math = client.getService<MathClient>('Math');
math.sum({ data: [1] }).subscribe({
next: r => logger.log('gRPC call ok', r),
error: e => logger.error('gRPC call failed', e),
}); Defensive patterns
Strategy: type-guard
Validate before calling
import { ClientGrpc } from '@nestjs/microservices';
// gRPC clients do not support on(); subscribe to per-call Observables instead
if (!('on' in client)) { /* skip */ } Type guard
import { ClientGrpc } from '@nestjs/microservices';
function isGrpcClient(c: unknown): c is ClientGrpc {
return typeof c === 'object' && c !== null && typeof (c as any).getService === 'function';
} Prevention
- 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.
When it happens
Trigger: Calling `clientGrpc.on('connected', cb)` (or any event) on a gRPC client proxy.
Common situations: Generic status/health reporting code that subscribes to events on every `ClientProxy`; copy-paste from another transport's connection handler.
Related errors
- The "connect()" method is not supported in gRPC mode.
- Method is not supported in gRPC mode. Use ClientGrpc instead
- 3
- Not initialized. Please call the "connect" method first.
- No consumer initialized. Please, call the "connect" method f
AI-assisted analysis of nestjs/nest@6ec0e2783d (2026-08-03).
Data as JSON: /data/errors/748a7adea0420dcb.json.
Report an issue: GitHub.