Angular AOT 编译错误“无法确定类组件的模块" [英] Angular AOT compilation error "cannot determine module for class Component''

查看:26
本文介绍了Angular AOT 编译错误“无法确定类组件的模块"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 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 {}

注意路由是如何在另一个模块中定义并导入到PrivateModuleAppTopBarComponentPrivateComponent's 模板中使用.所以两者都被使用和声明.但是当我使用 "node_modules/.bin/ngc" -p tsconfig-aot.json(我在 Windows 10 上)时,我收到此错误消息:无法确定 (path-to-project)/src/app/pages/private/private.component/private.component.ts 类 PrivateComponent 的模块!将 PrivateComponent 添加到 NgModule 以修复它.无法确定 (path-to-project)/src/app/pages/private/app.topbar.component.ts 中类 AppTopBarComponent 的模块!将 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 编译错误“无法确定类组件的模块"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆