【问题标题】:Differences between Angular compilationsAngular 编译之间的差异
【发布时间】:2020-10-16 19:50:04
【问题描述】:

当我编译我的应用程序时

ng build --prod

我有这个错误

ERROR in : Cannot determine the module for class AppComponent in D:/desarrollos/PatientPortal/front/src/app/customizations/database/app.component-database.ts! Add AppComponent to the NgModule to fix it.

但如果它编译使用

ng build --configuration=prod

编译正常,我的应用运行正常。

我看到不同之处在于第一个是使用 AOT 选项编译,但我不知道为什么会出现此错误,也不知道它是否重要(可能是关于我拥有的扩展类,但是对我很重要)。你能帮帮我吗?

【问题讨论】:

  • 您在哪个模块中声明了AppComponent?并且不要将它与默认的AppComponent 混淆。也许从/app.component-database.ts显示你的组件声明
  • 我有默认的 AppComponent 并复制它以使用不同的 app.component.html (需要服装)并在 angular.json 中替换它......但我没有声明,因为有一个替代品另一个
  • 如果只是 html 更改,请尝试保留相同的组件并仅替换 angular.json 中的 html。
  • 非常感谢,我这样做了,因为在这种情况下实际上不使用 .ts 文件,但有其他错误 ERROR in : Cannot determine the module for class BookappointmentsComponent in D:/desarrollos/PatientPortal/front/src/app/customizations/database/bookappointments.page-database.ts! Add BookappointmentsComponent to the NgModule to fix it. 在这种情况下我使用这个 .ts 文件
  • 这里的问题是BookappointmentsComponent在任何NgModule中都没有被引用。见:stackoverflow.com/questions/47119135/…

标签: angular aot angular-aot


【解决方案1】:

当你声明一个不属于任何模块的组件时,Angular 通常会报错。

如果您只想在构建时修改默认的AppComponent html 模板,您可以创建一个单独的html 模板并使用angular.json 中的fileReplacements 功能。

【讨论】:

  • 非常感谢,我这样做了,因为在这种情况下实际上不使用 .ts 文件,但有其他错误错误:无法确定 D:/desarrollos/ 中类 BookappointmentsComponent 的模块PatientPortal/front/src/app/customizations/database/bookappointments.page-database.ts!将 BookappointmentsComponent 添加到 NgModule 以修复它。在这种情况下,我使用这个 .ts 文件——
【解决方案2】:

我在 github 存储库中找到了帮助:

https://github.com/angular/angular/issues/38070

就我而言,我正在尝试使用@Component 装饰器而不是@Directive 装饰器来编译和抽象类。

【讨论】:

    猜你喜欢
    • 2019-04-30
    • 1970-01-01
    • 2012-02-11
    • 2012-02-25
    • 1970-01-01
    • 1970-01-01
    • 2013-02-24
    • 1970-01-01
    • 2021-01-15
    相关资源
    最近更新 更多