Skip to content
Latchkey

Angular "No NgModule metadata found for" in CI

The compiler was handed a class as an NgModule (in bootstrap, TestBed, or a lazy route) but that class has no @NgModule decorator. The reference points at the wrong class, or the decorator is missing.

What this error means

The build or a unit test fails with "No NgModule metadata found for 'AppComponent'" or a similar class name where a module was expected.

ng build
Error: No NgModule metadata found for 'AppComponent'.

Common causes

A component passed where a module is required

bootstrapModule, a lazy loadChildren, or TestBed.configureTestingModule was given a component or plain class instead of an @NgModule class.

A missing or stripped @NgModule decorator

The intended module class lost its @NgModule decorator, or an import resolved to the wrong file exporting a same-named class.

How to fix it

Point the reference at the real NgModule

  1. Confirm the class you bootstrap or lazy load is decorated with @NgModule.
  2. Fix the import so it references the module file, not a component.
  3. Rebuild or re-run the test.
main.ts
platformBrowserDynamic()
  .bootstrapModule(AppModule);

Use the standalone bootstrap API where appropriate

For standalone apps, bootstrap the root component with bootstrapApplication instead of an NgModule.

main.ts
bootstrapApplication(AppComponent, appConfig);

How to prevent it

  • Bootstrap and lazy load modules, not components.
  • Keep @NgModule on every module class.
  • Match standalone vs NgModule bootstrap to your app style.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →