title: Angular AOT compilation error "cannot determine module for class Component''
body: <p>I have an Angular (4.3.2) application on which I want to perform an AOT build. App was created using <code>@angular/cli</code>. I have two components scaffolded with <code>ng generate</code> and a module in which both are included as a declaration:</p>
  
  <pre><code>import {PrivateComponent} from './private.component/private.component';
  
  NgModule({
     imports: [
        // other imports
        PrivateRoutingModule
     ],
     declarations: [
        ...some other components, 
        PrivateComponent, 
        AppTopBarComponent
     ]
     // other stuff 
  }) 
  export class PrivateModule {}
  </code></pre>
  
  <p>Private component is also used in the module's routing:</p>
  
  <pre><code>const routes: Routes = [
    {path: '', component: PrivateComponent, children: // other components}
  ] 
  
  @NgModule({
     imports: [RouterModule.forChild(routes)] // this is the Angular built-in router module
  })
  export class PrivateRoutingModule {}
  </code></pre>
  
  <p>Notice how the routing was defined in another module and imported into <code>PrivateModule</code>
  The <code>AppTopBarComponent</code> is used inside the <code>PrivateComponent's</code> template. So both are used and declared. But when I use <code>"node_modules/.bin/ngc" -p tsconfig-aot.json</code> (I am on Windows 10), I get this error message:
  <code>Cannot determine the module for class PrivateComponent in (path-to-project)/src/app/pages/private/private.component/private.component.ts! Add PrivateComponent to the NgModule to fix it.</code>
  <code>Cannot determine the module for class AppTopBarComponent in (path-to-project)/src/app/pages/private/app.topbar.component.ts! Add AppTopBarComponent to the NgModule to fix it.</code>. My <code>tsconfig-aot.json</code> file is exactly the same as is in the <a href="https://angular.io/guide/aot-compiler" rel="noreferrer">Angular AOT build guide</a>.</p>