Skip to content

JIT application ignores NgModule providers from AOT-compiled library imported through a standalone component #69451

@AlessandroSomma

Description

@AlessandroSomma

Which @angular/* package(s) are the source of the bug?

Don't known / other

Is this a regression?

No

Description

When a JIT-compiled Angular application consumes a library compiled in AOT mode, providers defined in an NgModule may not be registered.

In the affected scenario, both the standalone component and the service are defined in the AOT-compiled library. The standalone component imports an NgModule from the same library, and that module provides a service.

When the standalone component is used from a JIT application, Angular fails to resolve the service dependency because the provider is not registered in any injector.

Expected behavior

Providers defined in an NgModule imported by a standalone component should be registered regardless of the compilation mode of the consuming application.

The behavior should be consistent across:

  • JIT application + JIT library
  • AOT application + AOT library
  • JIT application + AOT library

Actual behavior

In the JIT application + AOT library scenario:

  • Angular successfully processes the standalone component and its imports;
  • providers defined in imported NgModules are not registered;
  • dependency injection fails when Angular attempts to instantiate the standalone component.

Additional observations

The issue appears specific to the JIT consumer + AOT library combination.

The same reproduction works if:

  • the consuming application is compiled in AOT mode;
  • the service is provided directly by the standalone component instead of by the imported NgModule.

This suggests that provider metadata originating from NgModule is not correctly propagated when processed by the JIT runtime from an AOT-compiled library.

Please provide a link to a minimal reproduction of the bug

https://github.com/AlessandroSomma/angular-standalone-aot-jit-bug

Please provide the exception or error you saw

ERROR ɵNotFound: NG0201: No provider found for `MyService`. Source: AppModule.

Please provide the environment you discovered this bug in (run ng version)

Node 22
Angular 20

Anything else?

No response

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions