nestjs/nest · error · Error

The "connect()" method is not supported in gRPC mode.

Error message

The "connect()" method is not supported in gRPC mode.

What it means

`ClientGrpcProxy.connect()` unconditionally throws because gRPC clients open channels lazily per call via grpc-js and do not support the eager-connect lifecycle used by other transports. Calling `connect()` is a misuse of the `ClientGrpc` API surface.

Source

Thrown at packages/microservices/client/client-grpc.ts:362

        pkg = pkg[name];
      }
    }

    return pkg;
  }

  public close() {
    this.clients.forEach(client => {
      if (client && isFunction(client.close)) {
        client.close();
      }
    });
    this.clients.clear();
    this.grpcClients = [];
  }

  public async connect(): Promise<any> {
    throw new Error('The "connect()" method is not supported in gRPC mode.');
  }

  public send<TResult = any, TInput = any>(
    pattern: any,
    data: TInput,
  ): Observable<TResult> {
    throw new Error(
      'Method is not supported in gRPC mode. Use ClientGrpc instead (learn more in the documentation).',
    );
  }

  protected getClient(name: string): any {
    return this.grpcClients.find(client =>
      Object.hasOwnProperty.call(client, name),
    );
  }

  protected publish(packet: any, callback: (packet: any) => any): any {

View on GitHub (pinned to 6ec0e2783d)

Solutions

  1. Remove the explicit `connect()` call — for gRPC you obtain a service via `getService()` and call methods directly.
  2. Branch generic lifecycle code on transport type before calling `connect()`.
  3. Use the `@Client(() => ClientGrpc)` / `ClientsModule` pattern and skip manual connect.

Example fix

// before
const client = ClientProxyFactory.create({ transport: Transport.GRPC, options });
await client.connect();
// after
const client = ClientProxyFactory.create({ transport: Transport.GRPC, options }) as ClientGrpc;
const math = client.getService<IMathService>('Math');
math.sum({ data: [1, 2] }).subscribe(...);
Defensive patterns

Strategy: type-guard

Validate before calling

import { ClientGrpc, ClientProxy } from '@nestjs/microservices';
function supportsConnect(c: ClientProxy | ClientGrpc): boolean {
  return typeof (c as any).connect === 'function' && c.constructor.name !== 'ClientGrpcProxy';
}
if (supportsConnect(client)) await client.connect();

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

When it happens

Trigger: Calling `await clientGrpc.connect()` explicitly, or generic lifecycle code (e.g. an `onModuleInit` loop) that invokes `connect()` on every `ClientProxy` regardless of transport.

Common situations: Code copied from a TCP/Redis/NATS/MQTT example that calls `connect()`; a base class treating all clients uniformly; upgrading a transport from TCP to gRPC without removing the connect call.

Related errors


AI-assisted analysis of nestjs/nest@6ec0e2783d (2026-08-03). Data as JSON: /data/errors/287c50d85cd44a14.json. Report an issue: GitHub.