2017-08-31 58 views
1

我有在其上欲执行AOT构建。应用使用@angular/cli创建的角(4.3.2)应用程序。我有两个组成部分与脚手架和ng generate其中两个被包括作为声明的模块:角AOT编译错误“不能确定模块,用于类元器件'

import {PrivateComponent} from './private.component/private.component'; 

NgModule({ 
    imports: [ 
     // other imports 
     PrivateRoutingModule 
    ], 
    declarations: [ 
     ...some other components, 
     PrivateComponent, 
     AppTopBarComponent 
    ] 
    // other stuff 
}) 
export class PrivateModule {} 

私人分量也被在模块的路由中使用的:

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

通知路由是如何在另一个模块中定义并导入到PrivateModule AppTopBarComponent用于PrivateComponent's模板中。所以这两个都被使用和声明。但是当我使用"node_modules/.bin/ngc" -p tsconfig-aot.json(我在Windows 10上)时,出现此错误消息: 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.。我的tsconfig-aot.json文件与Angular AOT build guide中的完全相同。

+0

值得一提的我遇到的几个问题在这个问题上,但问题主要是未使用的组件。我的实际使用。 –

+0

您忘记了在'./private.component/private.component'的导入导入{PrivateComponent}中添加PrivateComponent; – Vega

+0

@Vega我的坏,我只是错过了它,而复制粘贴。它实际上存在于源代码 –

回答

4

我已经找到了一个解决方案。但问题是,PrivateComponent在另一个文件中导入,但没有用,就像这样:

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

显然ngc试图链接的一切,是由未使用的进口混淆