Skip to content

Commit

Permalink
docs: add NG0403.md for Bootstrapped NgModule doesn't specify which c…
Browse files Browse the repository at this point in the history
…omponent to initialize error (#48483)

- update `errors.ts` to annotate the error NG0403, so that the runtime can add a link to that guide when an error is thrown
- update `application_ref_spec.ts` to include the new link of the error
- update `errors.md` as a result of running `yarn bazel test packages/core/test`

Fixes #47985

PR Close #48483
  • Loading branch information
robertIsaac authored and alxhub committed Jan 4, 2023
1 parent 3944aa7 commit c5a8485
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
42 changes: 42 additions & 0 deletions aio/content/errors/NG0403.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
@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
2 changes: 1 addition & 1 deletion goldens/public-api/core/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const enum RuntimeErrorCode {
// (undocumented)
ASYNC_INITIALIZERS_STILL_RUNNING = 405,
// (undocumented)
BOOTSTRAP_COMPONENTS_NOT_FOUND = 403,
BOOTSTRAP_COMPONENTS_NOT_FOUND = -403,
// (undocumented)
CYCLIC_DI_DEPENDENCY = -200,
// (undocumented)
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const enum RuntimeErrorCode {
MULTIPLE_PLATFORMS = 400,
PLATFORM_NOT_FOUND = 401,
ERROR_HANDLER_NOT_FOUND = 402,
BOOTSTRAP_COMPONENTS_NOT_FOUND = 403,
BOOTSTRAP_COMPONENTS_NOT_FOUND = -403,
PLATFORM_ALREADY_DESTROYED = 404,
ASYNC_INITIALIZERS_STILL_RUNNING = 405,
APPLICATION_REF_ALREADY_DESTROYED = 406,
Expand Down
6 changes: 4 additions & 2 deletions packages/core/test/application_ref_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,10 @@ class SomeComponent {
waitForAsync(async () => {
defaultPlatform.bootstrapModule(await createModule({ngDoBootstrap: false}))
.then(() => expect(false).toBe(true), (e) => {
const expectedErrMsg =
`NG0403: The module MyModule was bootstrapped, but it does not declare "@NgModule.bootstrap" components nor a "ngDoBootstrap" method. Please define one of these.`;
const expectedErrMsg = `NG0403: The module MyModule was bootstrapped, ` +
`but it does not declare "@NgModule.bootstrap" components nor a "ngDoBootstrap" method. ` +
`Please define one of these. ` +
`Find more at https://angular.io/errors/NG0403`;
expect(e.message).toEqual(expectedErrMsg);
expect(mockConsole.res[0].join('#')).toEqual('ERROR#Error: ' + expectedErrMsg);
});
Expand Down

0 comments on commit c5a8485

Please sign in to comment.