asp.net-core Expected errors when generating Angular 2 components in .NET Core project (version 0.8.3)


Example

When generating new Angular 2 components in a .NET Core project, you may run into the following errors (as of version 0.8.3):

Error locating module for declaration
        SilentError: No module files found

OR

No app module found. Please add your new Class to your component. 
        Identical ClientApp/app/app.module.ts

[SOLUTION]

  1. Rename app.module.client.ts to app.client.module.ts

  2. Open app.client.module.ts: prepend the declaration with 3 dots “...” and wrap the declaration in brackets.

    For example: [...sharedConfig.declarations, <MyComponent>]

  3. Open boot-client.ts: update your import to use the new app.client.module reference.

    For example: import { AppModule } from './app/app.client.module';

  4. Now try to generate the new component: ng g component my-component

[EXPLANATION]

Angular CLI looks for a file named app.module.ts in your project, and tries to find a references for the declarations property to import the component. This should be an array (as the sharedConfig.declarations is), but the changes do not get applied

[SOURCES]