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-redis.ts:281
if (this.isManuallyClosed) {
return undefined;
}
if (!this.getOptionsProp(this.options, 'retryAttempts')) {
this.logger.error(
'Redis connection closed and retry attempts not specified',
);
return;
}
if (times > this.getOptionsProp(this.options, 'retryAttempts', 0)) {
this.logger.error(`Retry time exhausted`);
return;
}
return this.getOptionsProp(this.options, 'retryDelay', 5000);
}
public unwrap<T>(): T {
if (!this.pubClient || !this.subClient) {
throw new Error(
'Not initialized. Please call the "listen"/"startAllMicroservices" method before accessing the server.',
);
}
return [this.pubClient, this.subClient] as T;
}
public on<
EventKey extends keyof RedisEvents = keyof RedisEvents,
EventCallback extends RedisEvents[EventKey] = RedisEvents[EventKey],
>(event: EventKey, callback: EventCallback) {
if (this.subClient && this.pubClient) {
this.subClient.on(event, (...args: [any]) => callback('sub', ...args));
this.pubClient.on(event, (...args: [any]) => callback('pub', ...args));
} else {
this.pendingEventListeners.push({ event, callback });
}
}
}View on GitHub (pinned to 6ec0e2783d)
Solutions
- Call app.listen() or app.startAllMicroservices() before accessing the Redis server instance.
- Await listen() so the Redis connection is established before any access.
Example fix
const app = await NestFactory.createMicroservice(AppModule, opts); await app.listen(); const server = app.get(ServerRedis);
When it happens
Trigger: Thrown at packages/microservices/server/server-redis.ts:281 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/8aec8385e564bd20.json.
Report an issue: GitHub.