加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Angular AOT编译错误“无法确定类组件的模块”

发布时间:2020-12-17 08:50:47 所属栏目:安全 来源:网络整理
导读:我有一个Angular(4.3.2)应用程序,我想在其上执行AOT构建.应用程序是使用@ angular / cli创建的.我有两个使用ng generate搭建的组件和一个模块,其中两个都作为声明包含在内: import {PrivateComponent} from './private.component/private.component';NgModu
我有一个Angular(4.3.2)应用程序,我想在其上执行AOT构建.应用程序是使用@ angular / cli创建的.我有两个使用ng generate搭建的组件和一个模块,其中两个都作为声明包含在内:
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的模板中使用.所以两者都被使用和宣布.但是当我使用“node_modules / .bin / ngc”-p tsconfig-aot.json(我在Windows 10上)时,我收到以下错误消息:
无法确定(路径到项目)/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 build guide中的完全相同.

我实际上找到了一个解决方案.问题是PrivateComponent是在另一个文件中导入的,但没有使用,就像这样:
import { PrivateComponent } from '../private/private.component'; // not used anywhere

显然,ngc尝试链接所有内容,并被未使用的导入混淆

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读