{"record":{"id":"896a7e85d7814be5","repo":"nestjs/nest","slug":"nest-cannot-export-a-provider-module-that-is-not-a","errorCode":null,"errorMessage":"Nest cannot export a provider/module that is not a part of the currently processed module (${module}). Please verify whether the exported ${token} is available in this particular context.\n\nPossible Solutions:\n- Is ${token} part of the relevant providers/imports within ${module}?\n\nFor more common dependency resolution issues, see: https://docs.nestjs.com/faq/common-errors\n","messagePattern":"Nest cannot export a provider/module that is not a part of the currently processed module \\((.+?)\\)\\. Please verify whether the exported (.+?) is available in this particular context\\.\n\nPossible Solutions:\n- Is (.+?) part of the relevant providers/imports within (.+?)\\?\n\nFor more common dependency resolution issues, see: https://docs\\.nestjs\\.com/faq/common-errors\n","errorType":"exception","errorClass":"UnknownExportException","httpStatus":null,"severity":"critical","filePath":"packages/core/injector/module.ts","lineNumber":499,"sourceCode":"      return this._exports.add(this.validateExportedProvider(provide));\n    }\n    this._exports.add(this.validateExportedProvider(provide));\n  }\n\n  public validateExportedProvider(token: InjectionToken) {\n    if (this._providers.has(token)) {\n      return token;\n    }\n    const imports = iterate(this._imports.values())\n      .filter(item => !!item)\n      .map(({ metatype }) => metatype)\n      .filter(metatype => !!metatype)\n      .toArray();\n\n    if (!imports.includes(token as Type<unknown>)) {\n      const { name } = this.metatype;\n      const providerName = isFunction(token) ? (token as Function).name : token;\n      throw new UnknownExportException(providerName as string, name);\n    }\n    return token;\n  }\n\n  public addController(controller: Type<Controller>) {\n    this._controllers.set(\n      controller,\n      new InstanceWrapper({\n        token: controller,\n        name: controller.name,\n        metatype: controller,\n        instance: null!,\n        isResolved: false,\n        scope: getClassScope(controller),\n        durable: isDurable(controller),\n        host: this,\n      }),\n    );","sourceCodeStart":481,"sourceCodeEnd":517,"githubUrl":"https://github.com/nestjs/nest/blob/a3a31b96436a0c5fc33266a19c02cfa4fd2c03c0/packages/core/injector/module.ts#L481-L517","documentation":"Modules may only export what they own or what they import: `validateExportedToken` checks every entry of the `exports` array against the module's providers and imported module classes. If the token is neither, NestJS throws UnknownExportException ('Nest cannot export a provider/module that is not part of the currently processed module') at bootstrap. Exporting is a re-export, not a forward declaration.","triggerScenarios":"`exports: [SomeService]` where SomeService is provided by another module that is imported — you must export the imported module itself; exporting a token that was never declared in `providers`; exporting a provider from a DynamicModule while the static `exports` references a different token; copy-pasting an exports array from another module.","commonSituations":"Building feature modules that aggregate several sub-modules; refactoring providers between modules without updating exports; exporting interfaces/custom tokens whose provider is declared elsewhere; using forRoot()-style dynamic modules and exporting tokens the dynamic wrapper never declared.","solutions":["If the exported provider is declared locally, make sure the exact same token is in this module's `providers`.","If it comes from an imported module, export the imported module class instead: `exports: [FeatureModule]` with `imports: [FeatureModule]`.","Re-declare the provider in this module (`providers: [SomeService]`) if it should genuinely be provided here.","Check for token drift: `{ provide: 'X', ... }` must be exported as `'X'`, not as the class."],"exampleFix":"// before\n@Module({\n  imports: [CatsModule],          // CatsModule provides CatsService\n  exports: [CatsService],         // not owned by THIS module -> error\n})\nexport class PetsModule {}\n\n// after\n@Module({\n  imports: [CatsModule],\n  exports: [CatsModule],          // re-export the module that owns it\n})\nexport class PetsModule {}","handlingStrategy":"validation","validationCode":"// Fail fast at test time: exports must be a subset of providers ∪ imports\nimport 'reflect-metadata';\n\nfunction assertExportsDeclared(module: Function) {\n  const declared = new Set<any>([\n    ...(Reflect.getMetadata('providers', module) ?? []),\n    ...(Reflect.getMetadata('imports', module) ?? []),\n  ]);\n  for (const token of Reflect.getMetadata('exports', module) ?? []) {\n    if (!declared.has(token)) {\n      throw new Error(\n        `${module.name} exports ${String(token)} which is neither a provider nor an import`,\n      );\n    }\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await NestFactory.create(AppModule);\n} catch (e: any) {\n  if (/cannot export a provider/module/i.test(String(e?.message))) {\n    console.error(e.message); // names the token and module — fix exports/providers there\n    process.exit(1);\n  }\n  throw e;\n}","preventionTips":["When re-exporting from aggregated modules, export the imported module class, never its internal providers.","Run the assertExportsDeclared check over all modules in a wiring unit test.","For custom-token providers, export and provide the identical token literal from one constants module."],"tags":["module-configuration","exports","providers","imports","bootstrap"],"backgroundTag":"invalid-module-export","analyzedSha":"a3a31b96436a0c5fc33266a19c02cfa4fd2c03c0","analyzedAt":"2026-08-21T19:39:39.867Z","contentChangedAt":"2026-08-21T19:39:39.867Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}