nestjs/nest · warning
Global pipes registered after initialization will not be app
Error message
Global pipes registered after initialization will not be applied.
What it means
A NestJS microservice builds its pattern-handler proxies once, during init()/listen(). This warning is logged by NestMicroservice.useGlobalPipes when the registration happens after that point: the call still records the pipes in the ApplicationConfig and the graph inspector (as an orphaned enhancer), but they are wired in too late to run for the already-created handlers. Nothing throws; the pipes simply never execute.
Source
Thrown at packages/microservices/nest-microservice.ts:197
);
this.applicationConfig.useGlobalFilters(...filters);
filters.forEach(item =>
this.graphInspector.insertOrphanedEnhancer({
subtype: 'filter',
ref: item,
}),
);
return this;
}
/**
* Registers global pipes (will be used for every pattern handler).
*
* @param {...PipeTransform} pipes
*/
public useGlobalPipes(...pipes: PipeTransform<any>[]): this {
if (this.isInitialized) {
this.logger.warn(
'Global pipes registered after initialization will not be applied.',
);
}
pipes = this.applyInstanceDecoratorIfRegistered<PipeTransform<any>>(
...pipes,
);
this.applicationConfig.useGlobalPipes(...pipes);
pipes.forEach(item =>
this.graphInspector.insertOrphanedEnhancer({
subtype: 'pipe',
ref: item,
}),
);
return this;
}
/**View on GitHub (pinned to 3f8a0ce183)
Solutions
- Move every useGlobalPipes() call before `await app.listen()` / `await app.init()` in bootstrap — create, register enhancers, then listen.
- If timing cannot be guaranteed, apply the pipe per-handler with @UsePipes() on the message handler, which works regardless of registration order.
- In hybrid apps, register global pipes on the main INestApplication before startAllMicroservices() so they flow through the shared ApplicationConfig.
- Add CI log scanning that fails the build on this warning, since the pipe silently no-ops at runtime.
Example fix
// before const app = await NestFactory.createMicroservice(AppModule, opts); await app.listen(); app.useGlobalPipes(new ValidationPipe()); // warning: never applied // after const app = await NestFactory.createMicroservice(AppModule, opts); app.useGlobalPipes(new ValidationPipe()); await app.listen();
Defensive patterns
Strategy: validation
Validate before calling
// guard the registration: isInitialized is protected, so check via cast and fail fast on bad order
const app = await NestFactory.createMicroservice(AppModule, opts);
function assertNotInitialized(app: NestMicroservice, api: string) {
if ((app as any).isInitialized) {
throw new Error(`Bootstrap order bug: ${api} must be called before listen()/init()`);
}
}
assertNotInitialized(app, 'useGlobalPipes');
app.useGlobalPipes(new ValidationPipe());
await app.listen(); Prevention
- Register all global enhancers (pipes, interceptors, guards, filters) in one place: immediately after createMicroservice and before any await of listen()/init()
- Resolve async config first, then create and configure the app — never configure after listen
- Fail CI on this warning string in startup logs since the enhancer silently no-ops
- Prefer @UsePipes()/@UseInterceptors()/@UseGuards() decorators when registration timing cannot be guaranteed
When it happens
Trigger: Calling app.useGlobalPipes(new ValidationPipe()) after `await app.listen()` (listen() runs init() internally and flips the protected isInitialized flag), or after an explicit `await app.init()`. Also in hybrid apps when the instance returned by connectMicroservice() is configured after app.startAllMicroservices() has already initialized it.
Common situations: Bootstrap refactors that move enhancer registration into post-listen code; global pipes depending on async config (secrets manager, config service) that resolves only after startup; feature modules attempting to self-register global pipes late in the lifecycle; test suites that reuse an already-initialized microservice instance.
Related errors
- Cannot apply global interceptors: registration must occur be
- Cannot apply global guards: registration must occur before i
- Cannot apply global preRequest hooks: registration must occu
- Calling the "${methodName}" in the preview mode is not suppo
- RMQ broker has blocked the connection (flow control). Reason
AI-assisted analysis of nestjs/nest@3f8a0ce183 (2026-08-21).
Data as JSON: /api/errors/43b2ed6bb57cd012.
Report an issue: GitHub.