{"record":{"id":"85f55c3dd1eb86b9","repo":"nestjs/nest","slug":"metatype-name-is-decorated-with-controller","errorCode":null,"errorMessage":"\"${metatype.name}\" is decorated with @Controller() and cannot appear in the \"imports\" array of a module. Please move \"${metatype.name}\" to the \"controllers\" array of the importing module instead.\n\nScope [${scope}]\n","messagePattern":"\"(.+?)\" is decorated with @Controller\\(\\) and cannot appear in the \"imports\" array of a module\\. Please move \"(.+?)\" to the \"controllers\" array of the importing module instead\\.\n\nScope \\[(.+?)\\]\n","errorType":"exception","errorClass":"InvalidClassModuleException","httpStatus":null,"severity":"critical","filePath":"packages/core/scanner.ts","lineNumber":206,"sourceCode":"    | {\n        moduleRef: Module;\n        inserted: boolean;\n      }\n    | undefined\n  > {\n    const moduleToAdd = this.isForwardReference(moduleDefinition)\n      ? moduleDefinition.forwardRef()\n      : moduleDefinition;\n\n    if (this.isInjectable(moduleToAdd)) {\n      throw new InvalidClassModuleException(\n        moduleDefinition,\n        scope,\n        'provider',\n      );\n    }\n    if (this.isController(moduleToAdd)) {\n      throw new InvalidClassModuleException(\n        moduleDefinition,\n        scope,\n        'controller',\n      );\n    }\n    if (this.isExceptionFilter(moduleToAdd)) {\n      throw new InvalidClassModuleException(moduleDefinition, scope, 'filter');\n    }\n\n    return this.container.addModule(moduleToAdd, scope);\n  }\n\n  public async scanModulesForDependencies(\n    modules: Map<string, Module> = this.container.getModules(),\n  ) {\n    for (const [token, { metatype }] of modules) {\n      await this.reflectImports(metatype, token, metatype.name);\n      this.reflectProviders(metatype, token);","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/nestjs/nest/blob/dd75d7bd8c5e88048587e6768d36eb695f3e7a25/packages/core/scanner.ts#L188-L224","documentation":"The controller counterpart of the injectable-in-imports guard: a class bearing the @Controller() watermark in an `imports` array triggers InvalidClassModuleException — '\"X\" is decorated with @Controller() and cannot appear in the imports array of a module. Please move X to the controllers array of the importing module instead.' Controllers are never importable DI units; only modules are.","triggerScenarios":"Listing a controller class in `imports` instead of `controllers`; trying to 'share' a controller between modules by importing it (the correct pattern is re-declaring it in each module's controllers or restructuring); paste errors between the arrays.","commonSituations":"Wanting one controller to serve multiple modules; teams migrating from frameworks where route handlers are registered globally; array mix-ups during module splits.","solutions":["Move the class from `imports` to the `controllers` array of the same module.","To use a controller in another module, re-declare it in that module's `controllers` (controllers are scoped to their module) or move it to a shared module that both import.","If shared behavior (not routes) is the goal, extract it into an @Injectable() service and export that instead."],"exampleFix":"// before\n@Module({\n  imports: [OrdersController], // wrong array\n})\nexport class OrdersModule {}\n\n// after\n@Module({\n  controllers: [OrdersController],\n  providers: [OrdersService],\n})\nexport class OrdersModule {}","handlingStrategy":"type-guard","validationCode":"// Wiring test: nothing in imports arrays may be @Controller()\nimport { CONTROLLER_WATERMARK } from '@nestjs/common/constants';\nimport 'reflect-metadata';\n\nfunction assertNoControllersInImports(modules: Function[]) {\n  for (const m of modules) {\n    for (const imported of Reflect.getMetadata('imports', m) ?? []) {\n      const target = imported && 'forwardRef' in (imported as any) ? (imported as any).forwardRef() : imported;\n      if (typeof target === 'function' && Reflect.getMetadata(CONTROLLER_WATERMARK, target)) {\n        throw new Error(`${m.name}: @Controller() ${target.name} belongs in controllers, not imports`);\n      }\n    }\n  }\n}","typeGuard":"const isControllerClass = (v: any): boolean =>\n  typeof v === 'function' && !!Reflect.getMetadata('__controller__', v);","tryCatchPattern":null,"preventionTips":["Register controllers only in the controllers array of the module whose scope they serve.","To share controller behavior across modules, extract services into a shared module instead of importing controllers.","Add the watermark scan to wiring tests so array mix-ups fail before bootstrap."],"tags":["module-configuration","controller","imports","bootstrap"],"backgroundTag":"invalid-module-import","analyzedSha":"dd75d7bd8c5e88048587e6768d36eb695f3e7a25","analyzedAt":"2026-08-21T19:39:39.867Z","contentChangedAt":"2026-08-21T19:39:39.867Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}