2017-08-31 59 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試圖鏈接的一切,是由未使用的進口混淆