{"record":{"id":"3b50358ace6299bb","repo":"angular/angular","slug":"runtimeerrorcode-import-providers-from-standalone","errorCode":"RuntimeErrorCode.IMPORT_PROVIDERS_FROM_STANDALONE","errorMessage":"Importing providers supports NgModule or ModuleWithProviders but got a standalone component \"${stringifyForError(source)}\"","messagePattern":"Importing providers supports NgModule or ModuleWithProviders but got a standalone component \"(.+?)\"","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"packages/core/src/di/provider_collection.ts","lineNumber":167,"sourceCode":"}\n\nexport function internalImportProvidersFrom(\n  checkForStandaloneCmp: boolean,\n  ...sources: (ImportProvidersSource | AbstractType<unknown>)[]\n): Provider[] {\n  const providersOut: SingleProvider[] = [];\n  const dedup = new Set<Type<unknown> | AbstractType<unknown>>(); // already seen types\n  let injectorTypesWithProviders: InjectorTypeWithProviders<unknown>[] | undefined;\n\n  const collectProviders: WalkProviderTreeVisitor = (provider) => {\n    providersOut.push(provider);\n  };\n\n  deepForEach(sources, (source) => {\n    if ((typeof ngDevMode === 'undefined' || ngDevMode) && checkForStandaloneCmp) {\n      const cmpDef = getComponentDef(source);\n      if (cmpDef?.standalone) {\n        throw new RuntimeError(\n          RuntimeErrorCode.IMPORT_PROVIDERS_FROM_STANDALONE,\n          `Importing providers supports NgModule or ModuleWithProviders but got a standalone component \"${stringifyForError(\n            source,\n          )}\"`,\n        );\n      }\n    }\n\n    // Narrow `source` to access the internal type analogue for `ModuleWithProviders`.\n    const internalSource = source as Type<unknown> | InjectorTypeWithProviders<unknown>;\n    if (walkProviderTree(internalSource, collectProviders, [], dedup)) {\n      injectorTypesWithProviders ||= [];\n      injectorTypesWithProviders.push(internalSource);\n    }\n  });\n  // Collect all providers from `ModuleWithProviders` types.\n  if (injectorTypesWithProviders !== undefined) {\n    processInjectorTypesWithProviders(injectorTypesWithProviders, collectProviders);","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/angular/angular/blob/51cb07e98081ab7e4e84a9e0949266a8e19cca84/packages/core/src/di/provider_collection.ts#L149-L185","documentation":"importProvidersFrom walks only NgModule and ModuleWithProviders sources to collect providers. If one of the sources is a standalone component (its component def has standalone: true), Angular throws IMPORT_PROVIDERS_FROM_STANDALONE — standalone components expose providers through their own imports and defs, not through this NgModule-oriented API.","triggerScenarios":"importProvidersFrom(StandaloneComponent) inside bootstrapApplication providers, route providers, or EnvironmentInjector.create imports; copy-pasting entries from an NgModule imports array (which legitimately lists standalone components) into importProvidersFrom.","commonSituations":"Standalone migration where an NgModule was deleted and its imports moved wholesale into importProvidersFrom; trying to reuse a standalone feature component's providers at app level.","solutions":["Remove the standalone component from importProvidersFrom; pass only NgModules or ModuleWithProviders","If the feature lives in an NgModule (routing module, feature module), pass that module instead","If you need the component's providers at app level, restructure: put them in a dedicated NgModule or provide them directly via providers: [...] / makeEnvironmentProviders"],"exampleFix":"// before\nbootstrapApplication(AppComponent, {\n  providers: [importProvidersFrom(UserListComponent)], // UserListComponent is standalone\n});\n\n// after\nbootstrapApplication(AppComponent, {\n  providers: [importProvidersFrom(UserListModule), provideHttpClient()],\n});","handlingStrategy":"type-guard","validationCode":"function isStandaloneComponent(t: unknown): boolean {\n  return !!(t as any)?.ɵcmp?.standalone;\n}\n\nfor (const src of sources) {\n  if (isStandaloneComponent(src)) {\n    throw new Error(`${String(src)} is standalone; provide its providers directly instead.`);\n  }\n}\nconst providers = importProvidersFrom(...(sources as Type<unknown>[]));","typeGuard":"function isStandaloneComponent(t: unknown): t is Type<unknown> & {ɵcmp: {standalone: true}} {\n  return !!(t as any)?.ɵcmp?.standalone;\n}","tryCatchPattern":null,"preventionTips":["Only pass NgModules or ModuleWithProviders to importProvidersFrom","During standalone migration, never move imports-array entries wholesale into importProvidersFrom","Expose feature providers via providers arrays or EnvironmentProviders, not via standalone component types"],"tags":["dependency-injection","standalone","import-providers-from","bootstrap"],"backgroundTag":"standalone-vs-ngmodule-mismatch","analyzedSha":"51cb07e98081ab7e4e84a9e0949266a8e19cca84","analyzedAt":"2026-08-22T07:04:54.531Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}