{"id":"b0f25f3ae564135a","repo":"nestjs/nest","slug":"method-is-not-supported-for-grpc-transport","errorCode":null,"errorMessage":"Method is not supported for gRPC transport","messagePattern":"Method is not supported for gRPC transport","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/microservices/server/server-grpc.ts","lineNumber":333,"sourceCode":"\n  public createStreamServiceMethod(methodHandler: Function): Function {\n    return async (call: GrpcCall, callback: Function) => {\n      return this.onProcessingStartHook(\n        this.transportId,\n        { ...call, operationId: methodHandler.name } as any,\n        async () => {\n          const handler = methodHandler(call.request, call.metadata, call);\n          const result$ = this.transformToObservable(await handler);\n          await this.writeObservableToGrpc(result$, call);\n\n          this.onProcessingEndHook?.(this.transportId, call.request);\n        },\n      );\n    };\n  }\n\n  public unwrap<T>(): T {\n    throw new Error('Method is not supported for gRPC transport');\n  }\n\n  public on<\n    EventKey extends string | number | symbol = string | number | symbol,\n    EventCallback = any,\n  >(event: EventKey, callback: EventCallback) {\n    throw new Error('Method is not supported in gRPC mode.');\n  }\n\n  /**\n   * Writes an observable to a GRPC call.\n   *\n   * This function will ensure that backpressure is managed while writing values\n   * that come from an observable to a GRPC call.\n   *\n   * @param source The observable we want to write out to the GRPC call.\n   * @param call The GRPC call we want to write to.\n   * @returns A promise that resolves when we're done writing to the call.","sourceCodeStart":315,"sourceCodeEnd":351,"githubUrl":"https://github.com/nestjs/nest/blob/6ec0e2783d15290732447f304d8549b591b9749e/packages/microservices/server/server-grpc.ts#L315-L351","documentation":"Thrown by ServerGrpc.unwrap(). Unlike the TCP/Redis/RMQ/MQTT/NATS servers which hold a single raw broker handle, the gRPC server is built from many dynamically created service definitions and does not expose one underlying object to hand back; unwrap() is therefore permanently unsupported and always throws. This mirrors ClientKafka.on() and the ServerGrpc.on()/status guards — the API is intentionally absent for gRPC.","triggerScenarios":"Calling server.unwrap() (or microservice.unwrap() delegating to a gRPC server) to reach the raw @grpc/grpc-js Server. Generic introspection/tooling that calls unwrap() on every server type.","commonSituations":"Bootstrap code that grabs the raw driver via unwrap() across all transports, run against a gRPC server. Migrating from TCP/Redis to gRPC and keeping the unwrap() call. Custom instrumentation that expects a raw handle.","solutions":["Do not call unwrap() on a ServerGrpc; there is no single underlying handle to return.","For low-level gRPC access, register a custom service or use the gRPC client created via createClient() / ClientsModule instead.","In generic code, skip unwrap() when the transport is Transport.GRPC."],"exampleFix":"// before\nconst server = new ServerGrpc(options);\nconst grpcServer = server.unwrap(); // throws\n\n// after\nconst server = new ServerGrpc(options);\n// there is no raw handle; interact through the proto service clients instead","handlingStrategy":"type-guard","validationCode":"function unwrapSafe(server: any) {\n  if (server instanceof ServerGrpc) return undefined; // unsupported\n  return server.unwrap();\n}\nconst raw = unwrapSafe(server);","typeGuard":"import { ServerGrpc } from '@nestjs/microservices';\nconst supportsUnwrap = (s: any): boolean => !(s instanceof ServerGrpc);","tryCatchPattern":"try {\n  return server.unwrap();\n} catch (e) {\n  if (/not supported for gRPC transport/.test(e?.message)) { /* use gRPC service client */ }\n  else throw e;\n}","preventionTips":["Do not call unwrap() on a ServerGrpc; there is no single raw handle.","For low-level gRPC needs, register custom services or use the gRPC client.","Branch generic code by transport type."],"tags":["grpc","server","api-misuse","typescript"],"analyzedSha":"6ec0e2783d15290732447f304d8549b591b9749e","analyzedAt":"2026-08-03T17:42:23.673Z","schemaVersion":2}