nestjs/nest · error · Error
Not initialized. Please call the "listen"/"startAllMicroserv
Error message
Not initialized. Please call the "listen"/"startAllMicroservices" method before accessing the server.
What it means
Error "Not initialized. Please call the "listen"/"startAllMicroservices" method before accessing the server." thrown in nestjs/nest.
Source
Thrown at packages/microservices/server/server-rmq.ts:383
correlationId: string,
context: RmqContext,
): void {
const outgoingResponse = this.serializer.serialize(
message as unknown as OutgoingResponse,
);
const options = outgoingResponse.options;
delete outgoingResponse.options;
const buffer = Buffer.from(JSON.stringify(outgoingResponse));
const sendOptions = { correlationId, ...options };
this.onProcessingEndHook?.(this.transportId, context);
this.channel!.sendToQueue(replyTo, buffer, sendOptions);
}
public unwrap<T>(): T {
if (!this.server) {
throw new Error(
'Not initialized. Please call the "listen"/"startAllMicroservices" method before accessing the server.',
);
}
return this.server as T;
}
public on<
EventKey extends keyof RmqEvents = keyof RmqEvents,
EventCallback extends RmqEvents[EventKey] = RmqEvents[EventKey],
>(event: EventKey, callback: EventCallback) {
if (this.server) {
this.server.addListener(event, callback);
} else {
this.pendingEventListeners.push({ event, callback });
}
}
public getHandlerByPattern(pattern: string): MessageHandler | null {View on GitHub (pinned to 6ec0e2783d)
Solutions
- Call app.listen() or app.startAllMicroservices() before accessing the RMQ server instance.
- Await listen() so the RabbitMQ channel/connection is set up before use.
Example fix
const app = await NestFactory.createMicroservice(AppModule, opts); await app.listen(); const server = app.get(ServerRMQ);
When it happens
Trigger: Thrown at packages/microservices/server/server-rmq.ts:383 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of nestjs/nest@6ec0e2783d (2026-08-03).
Data as JSON: /data/errors/dca14831dbe43314.json.
Report an issue: GitHub.