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

2024-05-24

我有一个 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 The 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.. My tsconfig-aot.json文件与中的完全相同Angular AOT 构建指南 https://angular.io/guide/aot-compiler.


确保您不会意外地有两个文件声明相同的组件

如果我运行时位于错误的目录中,这种情况经常发生在我身上ng g c,并且不要立即删除错误生成的文件。

错误:无法确定类的模块 FeatureBoxGroupComponent 中 S:/.../src/app/common-widgets/feature-widgets/feature-box-group/feature-box-group.component.ts! 将FeatureBoxGroupComponent 添加到NgModule 来修复它。

在这个例子中我有FeatureBoxGroupComponent定义在两个地方:

src\app\common-widgets\feature-widgets\feature-box-group\feature-box-group.component.ts

src\app\feature-widgets\feature-box-group\feature-box-group.component.ts

当然,错误消息告诉我它有问题的确切文件 - 但很容易浏览它。

只需在文件中查找组件名称即可查看引用它的所有位置,并确保它只定义一次。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

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

  • Angular 4 在 @ViewChild 上使用 setter

    我有一个演示here https stackblitz com edit angular dgmnlf file app 2Fchild component ts 我正在尝试使用 ngIf 将元素添加到 DOM 后获取该元素的高度 我试图通
  • 如何在 Angular 2 karma jasmine 测试中从 JSON 文件加载模拟数据?

    我在写信业力茉莉花测试用例角2 我们遇到了在单独的 JSON 文件中模拟数据的需求 因为数据很大 希望确保代码整洁 为此我进行了很多搜索但没有找到合适的解决方案 我们已经使用以下方式模拟 HTTP 服务模拟后端 所以我们不能使用Angula
  • rxjs 主题应该在课堂上公开吗?

    假设我有两个类 您可以在其中观察一些可观察量 第一个例子 公共主题 class EventsPub public readonly onEnd new Subject
  • Passport-local-mongoose:createStrategy 不是函数/authenticate 不是函数

    我正在构建这个启动项目 https github com cj wang mean start tree 424e6056e33bb16874ae808daf3780d53309296f并尝试添加用户登录护照本地猫鼬 https www n
  • TypeScript 中的类型安全谓词函数

    我的目标是编写谓词函数 isNull and isUndefined例如 在 TypeScript 中满足以下条件 可以独立使用 array filter isNull 可以逻辑组合 array filter and not isNull
  • 以嵌套反应形式使用 setControl

    我想知道当我在另一个 formBuilder 组中有一个数组时 我必须做什么才能以反应形式使用 setControl 和 get 例如 this formulario this formBuilder group title this ra
  • 无法重新加载/刷新活动路线

    我最近更新了新的 RC3 和 Router3alpha 似乎有些事情发生了变化 我注意到单击活动路径的链接不再导致组件重新加载 如何使用新的 router3 实现此行为 我的链接看起来像 a Link1 a 为了测试我只是在 ngOnIni
  • Typescript Enum Object.values() 返回值

    为什么Object values and Object keys 总是同时给出键和值 考虑以下代码 enum Enum FOO BAR console log Object values Enum console log Object ke
  • 将样式添加到 mat-autocomplete 的 mat-option

    我有这个 HTML代码在这里 https stackblitz com edit angular mat autocomplete with selected value vx1uqg file src 2Fapp 2Fautocomple
  • 打字稿中的递归未定义

    我在组件内使用画布对象来生成图表 为了使其动画化 我递归地调用该方法 我不断收到错误消息 指出该方法未定义 不确定我需要如何构建它 任何帮助表示赞赏 Animate function protected animate draw to Cl
  • angular2 rc5 路由器服务单例

    我最近迁移到 Angular 2 RC 5 并将应用程序中的子模块转换为 NgModule 鉴于以下情况plunker https angular io resources live examples router ts plnkr htm
  • TypeScript:增强内置类型

    如何增强其中一种 内置 类型 例如数组 在 JS 中 我会做类似的事情 Array prototype shuffle function TypeScript 中的等价物是什么 TypeScript 中的类型是 开放式 的 所以你可以这样写
  • Angular 2+ 安全性;保护服务器上的延迟加载模块

    我有一个 Angular 2 应用程序 用户可以在其中输入个人数据 该数据在应用程序的另一部分进行分析 该部分仅适用于具有特定权限的人员 问题是我们不想让未经授权的人知道how我们正在分析这些数据 因此 如果他们能够在应用程序中查看模板 那
  • 相当于 $q.when 在角度 2 中

    我习惯使用 q使用角度 1 我正在迁移到角度 2 是否有等效的提供 when 方法 例如我需要迁移这个 service updateProDB rootScope connectionStatus q storageService send
  • Angular 6 + RxJS 6.0:如何将新元素推送到 Observable 包含的数组

    我从 firebase 服务器分块接收数据 同时渲染该数据需要一个坚持可观察包含数组的库 我不知何故无法将新的数据块推送到可观察到的现有数据块数组 从数据服务中 我通过主题的下一个调用并尝试添加新的 calEvent this homeWo
  • 在 Angular 中刷新 owl-carousel

    我对猫头鹰旋转木马有一些关于动态变化的问题 例如幻灯片的数量等 换句话说 旋转木马在进行一些更改后很容易损坏 我的方法是重新加载 刷新轮播 但如何呢 我在网上发现必须按班级刷新 owl trigger refresh owl carouse
  • cordova-plugin-geolocation watchPosition() 方法不起作用

    我正在开发 Ionic2 Angular2 Typescript 应用程序 我正在尝试使用 Cordova 的 Geolocation 插件 但是当我像这样调用 watchPosition 方法时http ionicframework co
  • 如何删除打字稿中的错误(错误:TS2339)?

    var out document getElementsByClassName myclass 0 out focus out select out selectionStart 1 我试图在我的打字稿文件中执行此操作 但由于某种原因它给了
  • Angular2 中自定义指令和组件之间的通信

    我有一个模板 其中包含文本框 一个 span 标签和一个 div 标签 div 标签具有 selectedColor 自定义指令 我想在输入值更改时更改 span 和 div 标签的背景颜色 所以最后我希望我的指令对输入更改做出反应并设置
  • Angular 6 - WebSocket 在连接建立之前关闭

    每次我开始我的应用程序时 我都会得到这个 我不使用 SSL 并且连接到 localhost 4200 WebSocket 在连接建立之前关闭 什么会导致这种情况呢 我在 asp net core 和 Angular 7 2 0 中也遇到了这

随机推荐