在 Angular 上激活 Ivy 编译器时出错 10 错误 NG6003-无法解析为 NgModule

Error when activate Ivy compiler on Angular 10 error NG6003-could not resolve to a NgModule

我们最近将我们的应用程序迁移到 Angular 10 和 PrimeNG 9,现在我们正准备将这些框架迁移到最新版本。

我们正在努力准备我们的应用程序以进行迁移,并希望按照 Angular 的建议使用 Ivy 编译器。

但是当激活 Ivy 编译器并将 aot 设置为 true 时,它​​会在构建时显示以下错误:

ERROR in node_modules/@maestro-ng/primeng/maestro-primeng.module.d.ts:1:22 - error NG6003: Appears in the NgModule.exports of AppSharedModule, but could not be resolved to an NgModule, Component, Directive, or Pipe class.

This likely means that the library (@maestro-ng/primeng) which declares MaestroPrimengModule has not been processed correctly by ngcc, or is not compatible with Angular Ivy. Check if a newer version of the library is available, and update if so. Also consider checking with the library's authors to see if the library is expected to be compatible with Ivy.

这是完整的package.json:

{
  "name": "codex-frontend",
  "version": "1.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "dev": "ng serve -c dev --watch=false",
    "postinstall": "ngcc",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^10.2.5",
    "@angular/cdk": "^10.2.7",
    "@angular/common": "^10.2.5",
    "@angular/compiler": "^10.2.5",
    "@angular/core": "^10.2.5",
    "@angular/forms": "^10.2.5",
    "@angular/platform-browser": "^10.2.5",
    "@angular/platform-browser-dynamic": "^10.2.5",
    "@angular/router": "^10.2.5",
    "@fortawesome/fontawesome-free": "5.15.4",
    "@fullcalendar/core": "5.9.0",
    "@maestro-ng/core": "https://nexus.myorg.com.br/repository/npm-all/@maestro-ng/core/-/core-1.10.0.tgz",
    "@maestro-ng/primeng": "https://nexus.myorg.com.br/repository/npm-all/@maestro-ng/primeng/-/primeng-1.10.0.tgz",
    "@types/pdfjs-dist": "2.7.5",
    "bootstrap": "5.1.1",
    "chart.js": "3.5.1",
    "core-js": "3.18.0",
    "g": "2.0.1",
    "jquery": "3.6.0",
    "js-base64": "3.7.2",
    "moment": "2.29.1",
    "ng2-currency-mask": "9.0.2",
    "ng2-pdfjs-viewer": "6.0.2",
    "ngx-moment": "5.0.0",
    "pdfjs-dist": "2.9.359",
    "@popperjs/core": "2.10.1",
    "primeflex": "2.0.0",
    "primeicons": "4.0.0",
    "primeng": "9.1.3",
    "quill": "1.3.7",
    "rxjs": "6.6.2",
    "simple-pdf-viewer": "2.0.3",
    "tslib": "2.3.1",
    "zone.js": "^0.10.3"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.1000.8",
    "@angular/cli": "^10.2.3",
    "@angular/compiler-cli": "10.2.5",
    "@angular/language-service": "10.2.5",
    "@fortawesome/fontawesome-free": "5.8.2",
    "@types/jasmine": "3.9.1",
    "@types/jasminewd2": "2.0.10",
    "@types/node": "16.9.6",
    "codelyzer": "6.0.2",
    "jasmine-core": "3.9.0",
    "jasmine-spec-reporter": "7.0.0",
    "karma": "6.3.4",
    "karma-chrome-launcher": "3.1.0",
    "karma-cli": "2.0.0",
    "karma-coverage-istanbul-reporter": "3.0.3",
    "karma-jasmine": "4.0.1",
    "karma-jasmine-html-reporter": "1.7.0",
    "protractor": "7.0.0",
    "ts-node": "10.2.1",
    "tslint": "^5.20.1",
    "tslint-eslint-rules": "^5.4.0",
    "typescript": "3.9.7"
  }
}

即使使用 `"postinstall": "ngcc" 它也不起作用。

是否可以将 Ivy 与 Angular 10 和 PrimeNG 9 一起使用,我们需要先将 PrimeNG 迁移到 10?

PrimeNG 与 Angular 主要版本一致。

PrimeNG 10 依赖于Angular10,PrimeNG 11 依赖于Angular11.

您可以在 here

上找到官方信息来源

错误是由不是使用 Ivy 构建的内部库引起的。

如果您因为公司的内部库而遇到此错误,请确保该库是使用 Ivy 构建的,您可能已经知道,ViewEngine is deprecated and will be removed soon