{"record":{"id":"43b2ed6bb57cd012","repo":"nestjs/nest","slug":"global-pipes-registered-after-initialization-will","errorCode":null,"errorMessage":"Global pipes registered after initialization will not be applied.","messagePattern":"Global pipes registered after initialization will not be applied\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/microservices/nest-microservice.ts","lineNumber":197,"sourceCode":"    );\n    this.applicationConfig.useGlobalFilters(...filters);\n    filters.forEach(item =>\n      this.graphInspector.insertOrphanedEnhancer({\n        subtype: 'filter',\n        ref: item,\n      }),\n    );\n    return this;\n  }\n\n  /**\n   * Registers global pipes (will be used for every pattern handler).\n   *\n   * @param {...PipeTransform} pipes\n   */\n  public useGlobalPipes(...pipes: PipeTransform<any>[]): this {\n    if (this.isInitialized) {\n      this.logger.warn(\n        'Global pipes registered after initialization will not be applied.',\n      );\n    }\n\n    pipes = this.applyInstanceDecoratorIfRegistered<PipeTransform<any>>(\n      ...pipes,\n    );\n    this.applicationConfig.useGlobalPipes(...pipes);\n    pipes.forEach(item =>\n      this.graphInspector.insertOrphanedEnhancer({\n        subtype: 'pipe',\n        ref: item,\n      }),\n    );\n    return this;\n  }\n\n  /**","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/nestjs/nest/blob/3f8a0ce1832fb30053f55856088371b097bbf7e1/packages/microservices/nest-microservice.ts#L179-L215","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nconst app = await NestFactory.createMicroservice(AppModule, opts);\nawait app.listen();\napp.useGlobalPipes(new ValidationPipe()); // warning: never applied\n\n// after\nconst app = await NestFactory.createMicroservice(AppModule, opts);\napp.useGlobalPipes(new ValidationPipe());\nawait app.listen();","handlingStrategy":"validation","validationCode":"// guard the registration: isInitialized is protected, so check via cast and fail fast on bad order\nconst app = await NestFactory.createMicroservice(AppModule, opts);\nfunction assertNotInitialized(app: NestMicroservice, api: string) {\n  if ((app as any).isInitialized) {\n    throw new Error(`Bootstrap order bug: ${api} must be called before listen()/init()`);\n  }\n}\nassertNotInitialized(app, 'useGlobalPipes');\napp.useGlobalPipes(new ValidationPipe());\nawait app.listen();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["nestjs","microservices","pipes","lifecycle","bootstrap-order"],"backgroundTag":"global-enhancers-after-initialization","analyzedSha":"3f8a0ce1832fb30053f55856088371b097bbf7e1","analyzedAt":"2026-08-21T19:39:39.867Z","contentChangedAt":"2026-08-21T19:39:39.867Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}