{"record":{"id":"e56204ce369e6b0c","repo":"nestjs/nest","slug":"metatype-name-is-decorated-with-injectable","errorCode":null,"errorMessage":"\"${metatype.name}\" is decorated with @Injectable() and cannot appear in the \"imports\" array of a module. Please move \"${metatype.name}\" to the \"providers\" array of the importing module instead.\n\nScope [${scope}]\n","messagePattern":"\"(.+?)\" is decorated with @Injectable\\(\\) and cannot appear in the \"imports\" array of a module\\. Please move \"(.+?)\" to the \"providers\" array of the importing module instead\\.\n\nScope \\[(.+?)\\]\n","errorType":"exception","errorClass":"InvalidClassModuleException","httpStatus":null,"severity":"critical","filePath":"packages/core/scanner.ts","lineNumber":199,"sourceCode":"    return [moduleInstance].concat(registeredModuleRefs);\n  }\n\n  public async insertModule(\n    moduleDefinition: any,\n    scope: Type<unknown>[],\n  ): Promise<\n    | {\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  }","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/nestjs/nest/blob/dd75d7bd8c5e88048587e6768d36eb695f3e7a25/packages/core/scanner.ts#L181-L217","documentation":"Before registering an import the scanner checks watermarks: a class carrying the @Injectable() watermark is a provider, not a module, and putting it in `imports` throws InvalidClassModuleException — '\"X\" is decorated with @Injectable() and cannot appear in the imports array of a module. Please move X to the providers array of the importing module instead.' DI can only inject providers from modules, so the array would be meaningless anyway.","triggerScenarios":"Adding a service class to `imports` instead of `providers` (the two arrays are easy to confuse for newcomers); moving entries between arrays during refactoring and dropping them in the wrong one; importing a class decorated with a custom decorator that internally applies @Injectable().","commonSituations":"First NestJS projects wiring services; copying module templates and pasting service names into the wrong array; code reviews missing array mix-ups because TypeScript accepts any constructor in both arrays without strict typing.","solutions":["Move the class from `imports` to the `providers` array of the same module.","If the class depends on providers from other modules, keep it in `providers` and add the required modules to `imports`.","Consume it elsewhere via export: `exports: [TheService]` on the owning module."],"exampleFix":"// before\n@Module({\n  imports: [CatsService],   // wrong array\n})\nexport class CatsModule {}\n\n// after\n@Module({\n  providers: [CatsService],\n  exports: [CatsService],\n})\nexport class CatsModule {}","handlingStrategy":"type-guard","validationCode":"// Wiring test: nothing in imports arrays may be @Injectable()\nimport { INJECTABLE_WATERMARK } from '@nestjs/common/constants';\nimport 'reflect-metadata';\n\nfunction assertNoInjectablesInImports(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(INJECTABLE_WATERMARK, target)) {\n        throw new Error(`${m.name}: @Injectable() ${target.name} belongs in providers, not imports`);\n      }\n    }\n  }\n}","typeGuard":"const isInjectableClass = (v: any): boolean =>\n  typeof v === 'function' && !!Reflect.getMetadata('__injectable__', v);","tryCatchPattern":null,"preventionTips":["Run the imports-array watermark scan above over all modules in a unit test.","Keep arrays short and ordered (imports → controllers → providers) in every module to reduce mix-ups.","Code-review rule: imports takes modules only; anything with @Injectable goes to providers."],"tags":["module-configuration","injectable","providers","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"}