Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 19 - Component AppComponent is standalone, and cannot be declared in an NgModule

On my Angular v19 app I get the following error:

Component AppComponent is standalone, and cannot be declared in an NgModule

or

'imports' is only valid on a component that is standalone.

It worked perfectly in v18 before the update.

What happened?

like image 824
Matthieu Riegler Avatar asked Jan 24 '26 19:01

Matthieu Riegler


1 Answers

In v19, Angular swapped the default value for standalone from false to true. It means that every component declared is now implicitly standalone.

If your app relies on NgModule that declare components/pipes/directives, you will need to add standalone: false to all of those:

@Component({
  standalone: false,  // this is now required when using NgModule
  ...
})
export class AppComponent {}

@NgModule({
  declaration: [AppComponent], 
  ...
})
export class AppModule {}

Also, as part of the migration/update experience, the Angular team provides a migration schematic to update your apps and take care of most of the breaking changes. For this you only need to run ng update.

Make sure to also have a look at the update guide.

like image 96
Matthieu Riegler Avatar answered Jan 26 '26 13:01

Matthieu Riegler