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

  1. Move every useGlobalPipes() call before `await app.listen()` / `await app.init()` in bootstrap — create, register enhancers, then listen.
  2. If timing cannot be guaranteed, apply the pipe per-handler with @UsePipes() on the message handler, which works regardless of registration order.
  3. In hybrid apps, register global pipes on the main INestApplication before startAllMicroservices() so they flow through the shared ApplicationConfig.
  4. 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

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


AI-assisted analysis of nestjs/nest@3f8a0ce183 (2026-08-21). Data as JSON: /api/errors/43b2ed6bb57cd012. Report an issue: GitHub.