Angular AOT编译错误“无法确定类Component的模块” [英] Angular AOT compilation error "cannot determine module for class Component''
问题描述
我有一个Angular(4.3.2)应用程序,我想在该应用程序上执行AOT构建。应用是使用 @ angular / cli
创建的。我有两个用 ng generate
组成的支架,和一个都包含为声明的模块:
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 {}
注意如何在另一个模块中定义路由并将其导入到 PrivateModule
AppTopBarComponent
在 PrivateComponent的
模板中使用。因此,两者都被使用和声明。但是当我使用 node_modules / .bin / ngc -p tsconfig-aot.json
(我在Windows 10上)时,出现以下错误消息:
无法在(项目路径)/src/app/pages/private/private.component/private.component.ts中确定类PrivateComponent的模块!
无法在(路径到项目)/ src / app / pages / private /中确定AppTopBarComponent类的模块。 app.topbar.component.ts!将AppTopBarComponent添加到NgModule中进行修复。
。我的 tsconfig-aot.json
文件与 Angular AOT构建指南。
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.
推荐答案
我实际上找到了解决方案。问题是 PrivateComponent
导入了另一个文件,但没有使用,就像这样:
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
显然是 ngc
次尝试链接所有内容,并因未使用的导入而感到困惑
Apparently ngc
tries to link everything and is confused by an unused import
这篇关于Angular AOT编译错误“无法确定类Component的模块”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!