angular/aio/content/errors/NG0403.md

43 lines
1.6 KiB
Markdown
Raw Normal View History

@name Bootstrapped NgModule doesn't specify which component to initialize
@category runtime
@shortDescription An NgModule that was used for bootstrapping does not specify which component should be initialized.
@description
This error means that an NgModule that was used for bootstrapping an application is missing key information for Angular to proceed with the bootstrap process.
The error happens when the NgModule `bootstrap` property is missing (or is an empty array) in the `@NgModule` annotation and there is no `ngDoBootstrap` lifecycle hook defined on that NgModule class.
More information about the bootstrapping process can be found in [this guide](guide/bootstrapping).
The following examples will trigger the error.
```typescript
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, AppRoutingModule],
providers: [],
})
export class AppModule {}
// The `AppModule` is used for bootstrapping, but the `@NgModule.bootstrap` field is missing.
platformBrowser().bootstrapModule(AppModule);
```
```typescript
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, AppRoutingModule],
providers: [],
bootstrap: [],
})
export class AppModule {}
// The `AppModule` is used for bootstrapping, but the `@NgModule.bootstrap` field contains an empty array.
platformBrowser().bootstrapModule(AppModule);
```
@debugging
Please make sure that the NgModule that is used for bootstrapping is setup correctly:
- either the `bootstrap` property exists (and contains a non-empty array) in the `@NgModule` annotation
- or the `ngDoBootstrap` method exists on the NgModule class