Angular AOT compilation error \"cannot determine module for class Component''

匿名 (未验证) 提交于 2019-12-03 08:57:35

问题:

I have an Angular (4.3.2) application on which I want to perform an AOT build. App was created using @angular/cli. I have two components scaffolded with ng generate and a module in which both are included as a declaration:

import {PrivateComponent} from './private.component/private.component';  NgModule({    imports: [       // other imports       PrivateRoutingModule    ],    declarations: [       ...some other components,        PrivateComponent,        AppTopBarComponent    ]    // other stuff  })  export class PrivateModule {} 

Private component is also used in the module's routing:

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 {} 

Notice how the routing was defined in another module and imported into PrivateModule The AppTopBarComponent is used inside the PrivateComponent's template. So both are used and declared. But when I use "node_modules/.bin/ngc" -p tsconfig-aot.json (I am on Windows 10), I get this error message: 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. 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.. My tsconfig-aot.json file is exactly the same as is in the Angular AOT build guide.

回答1:

I have actually found a solution. The problem was that PrivateComponent was imported in another file, but not used, just like this:

import { PrivateComponent } from '../private/private.component'; // not used anywhere 

Apparently ngc tries to link everything and is confused by an unused import



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!