angular/angular · error · RuntimeError
RuntimeErrorCode.IMPORT_PROVIDERS_FROM_STANDALONE
RuntimeErrorCode.IMPORT_PROVIDERS_FROM_STANDALONE
Error message
Importing providers supports NgModule or ModuleWithProviders but got a standalone component "${stringifyForError(source)}" What it means
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.
Source
Thrown at packages/core/src/di/provider_collection.ts:167
}
export function internalImportProvidersFrom(
checkForStandaloneCmp: boolean,
...sources: (ImportProvidersSource | AbstractType<unknown>)[]
): Provider[] {
const providersOut: SingleProvider[] = [];
const dedup = new Set<Type<unknown> | AbstractType<unknown>>(); // already seen types
let injectorTypesWithProviders: InjectorTypeWithProviders<unknown>[] | undefined;
const collectProviders: WalkProviderTreeVisitor = (provider) => {
providersOut.push(provider);
};
deepForEach(sources, (source) => {
if ((typeof ngDevMode === 'undefined' || ngDevMode) && checkForStandaloneCmp) {
const cmpDef = getComponentDef(source);
if (cmpDef?.standalone) {
throw new RuntimeError(
RuntimeErrorCode.IMPORT_PROVIDERS_FROM_STANDALONE,
`Importing providers supports NgModule or ModuleWithProviders but got a standalone component "${stringifyForError(
source,
)}"`,
);
}
}
// Narrow `source` to access the internal type analogue for `ModuleWithProviders`.
const internalSource = source as Type<unknown> | InjectorTypeWithProviders<unknown>;
if (walkProviderTree(internalSource, collectProviders, [], dedup)) {
injectorTypesWithProviders ||= [];
injectorTypesWithProviders.push(internalSource);
}
});
// Collect all providers from `ModuleWithProviders` types.
if (injectorTypesWithProviders !== undefined) {
processInjectorTypesWithProviders(injectorTypesWithProviders, collectProviders);View on GitHub (pinned to 51cb07e980)
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
Example fix
// before
bootstrapApplication(AppComponent, {
providers: [importProvidersFrom(UserListComponent)], // UserListComponent is standalone
});
// after
bootstrapApplication(AppComponent, {
providers: [importProvidersFrom(UserListModule), provideHttpClient()],
}); Defensive patterns
Strategy: type-guard
Validate before calling
function isStandaloneComponent(t: unknown): boolean {
return !!(t as any)?.ɵcmp?.standalone;
}
for (const src of sources) {
if (isStandaloneComponent(src)) {
throw new Error(`${String(src)} is standalone; provide its providers directly instead.`);
}
}
const providers = importProvidersFrom(...(sources as Type<unknown>[])); Type guard
function isStandaloneComponent(t: unknown): t is Type<unknown> & {ɵcmp: {standalone: true}} {
return !!(t as any)?.ɵcmp?.standalone;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- PROVIDER_IN_WRONG_CONTEXT
- Trying to get the AngularJS injector before it being set.
- Configuration error: found both withXsrfConfiguration() and
- Configuration error: withRequestsMadeViaParent() cannot be c
- withRequestsMadeViaParent() can only be used when the parent
AI-assisted analysis of angular/angular@51cb07e980 (2026-08-22).
Data as JSON: /api/errors/3b50358ace6299bb.
Report an issue: GitHub.