nestjs/nest · error · Error

Method not implemented.

Error message

Method not implemented.

What it means

Thrown by the base ClientProxy.on() default implementation. ClientProxy declares on() as a non-abstract method that always throws 'Method not implemented.' so that subclasses opt in by overriding it (ClientRedis, ClientRMQ, ClientMQTT, ClientTCP, ClientNATS override it; ClientKafka overrides with its own 'not supported' error). Hitting this base message means you are using a client class whose transport does not implement event subscription via on() — typically the legacy ClientProxyDirect or a custom subclass that never overrode on().

Source

Thrown at packages/microservices/client/client-proxy.ts:71

  /**
   * Establishes the connection to the underlying server/broker.
   */
  public abstract connect(): Promise<any>;
  /**
   * Closes the underlying connection to the server/broker.
   */
  public abstract close(): any;
  /**
   * Registers an event listener for the given event.
   * @param event Event name
   * @param callback Callback to be executed when the event is emitted
   */
  public on<
    EventKey extends keyof EventsMap = keyof EventsMap,
    EventCallback extends EventsMap[EventKey] = EventsMap[EventKey],
  >(event: EventKey, callback: EventCallback) {
    throw new Error('Method not implemented.');
  }
  /**
   * Returns an instance of the underlying server/broker instance,
   * or a group of servers if there are more than one.
   */
  public abstract unwrap<T>(): T;

  /**
   * Send a message to the server/broker.
   * Used for message-driven communication style between microservices.
   * @param pattern Pattern to identify the message
   * @param data Data to be sent
   * @returns Observable with the result
   */
  public send<TResult = any, TInput = any>(
    pattern: any,
    data: TInput,
  ): Observable<TResult> {

View on GitHub (pinned to 6ec0e2783d)

Solutions

  1. Override on() in your custom ClientProxy subclass, or use one of the built-in transport clients that implement it (Redis/RMQ/MQTT/TCP/NATS).
  2. If you only need connection status, subscribe to client.status instead of on().
  3. Switch to a transport client that supports on(), or implement the listener against the unwrapped native client.

Example fix

// before
class MyClient extends ClientProxy {
  connect() { return Promise.resolve(); }
  close() {}
  unwrap<T>(): T { return null as T; }
}
new MyClient().on('connect', fn); // throws 'Method not implemented.'

// after
class MyClient extends ClientProxy {
  on(event, cb) { this._status$.subscribe(s => s === 'connected' && cb()); }
  // ...
}
Defensive patterns

Strategy: type-guard

Validate before calling

// Only call on() on clients that implement it
const transportsWithoutOn = new Set([/* custom ClientProxy subclasses without on() */]);
function supportsOn(client: any): boolean {
  return client && typeof client.on === 'function'
    && client.on !== ClientProxy.prototype.on;
}
if (supportsOn(client)) client.on('connect', fn);
else client.status.subscribe(s => { /* ... */ });

Type guard

import { ClientProxy } from '@nestjs/microservices';
const hasOverriddenOn = (c: any): boolean =>
  c instanceof ClientProxy && c.on !== ClientProxy.prototype.on;

Try / catch

try {
  client.on(event, cb);
} catch (e) {
  if (/Method not implemented/.test(e?.message)) {
    client.status.subscribe(s => { /* handle via status */ });
  } else throw e;
}

Prevention

When it happens

Trigger: Calling on() on a ClientProxy subclass that did not override it (e.g., a custom client extending ClientProxy directly, or ClientProxyFactory returning a client type that has no on() override). Writing generic code that calls on() on any ClientProxy without checking the concrete transport.

Common situations: Custom ClientProxy subclass authored without overriding on()/unwrap()/connect(). Code that assumes every ClientProxy supports the on() API like the Redis/TCP transports do. Stale references to a client type whose on() was never implemented.

Related errors


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