错误NG6002:出现在<module>的NgModule.imports中,但无法解析为NgModule类

时间:2020-02-19 08:38:46

标签: angular angular-ivy

我刚刚从Angular 8.2更新到了9。

如果禁用常春藤,一切都会很好,但是启用常春藤时,我会收到很多似乎有些晦涩的错误,至少在谷歌搜索时找不到任何结果。

我很确定我已经完成了更新所需的一切,即更改了延迟加载以使用动态导入和固定的Angular Material导入路径等。

我还将在此处包括我的 package.json 依赖项

  "dependencies": {
    "@angular/animations": "^9.0.0",
    "@angular/cdk": "^9.0.0",
    "@angular/common": "^9.0.0",
    "@angular/compiler": "^9.0.0",
    "@angular/core": "^9.0.0",
    "@angular/fire": "^5.4.2",
    "@angular/flex-layout": "^9.0.0-beta.29",
    "@angular/forms": "^9.0.0",
    "@angular/http": "^7.2.15",
    "@angular/material": "^9.0.0",
    "@angular/material-moment-adapter": "^8.2.2",
    "@angular/platform-browser": "^9.0.0",
    "@angular/platform-browser-dynamic": "^9.0.0",
    "@angular/platform-server": "^9.0.0",
    "@angular/router": "^9.0.0",
    "@ngrx/effects": "^8.3.0",
    "@ngrx/entity": "^8.3.0",
    "@ngrx/router-store": "^8.3.0",
    "@ngrx/store": "^8.3.0",
    "@zxing/ngx-scanner": "^2.0.1",
    "angular-resizable-element": "^3.2.4",
    "angular-resize-event": "^1.1.1",
    "angular2-highcharts": "^0.5.5",
    "core-js": "^3.6.4",
    "detect-browser": "^4.7.0",
    "firebase": "^7.8.0",
    "google-polyline": "^1.0.3",
    "hammerjs": "^2.0.8",
    "highcharts": "^8.0.0",
    "i18n-iso-countries": "^4.3.1",
    "leaflet": "^1.5.1",
    "mapbox-gl": "^1.4.0",
    "moment": "^2.24.0",
    "moment-timezone": "^0.5.26",
    "ng-pick-datetime": "^6.0.7",
    "ngrx-store-freeze": "^0.2.3",
    "ngx-cacheable": "^1.3.2",
    "ngx-cookie-service": "^2.2.0",
    "ngx-csv": "^0.3.1",
    "ngx-file-drop": "^8.0.8",
    "ngx-infinite-scroll": "^0.8.4",
    "papaparse": "^5.0.2",
    "request": "^2.87.0",
    "request-promise": "^4.2.2",
    "rxjs": "^6.5.4",
    "rxjs-compat": "^6.3.3",
    "typescript-string-operations": "^1.3.1",
    "web-animations-js": "^2.3.2",
    "zone.js": "^0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.900.1",
    "@angular/cli": "^9.0.0",
    "@angular/compiler-cli": "^9.0.0",
    "@angular/language-service": "^9.0.0",
    "@ngrx/store-devtools": "^8.3.0",
    "@types/body-parser": "^1.17.0",
    "@types/cors": "^2.8.4",
    "@types/detect-browser": "^4.0.0",
    "@types/express": "^4.11.1",
    "@types/firebase": "^3.2.1",
    "@types/helmet": "0.0.37",
    "@types/jasmine": "^3.5.4",
    "@types/jasminewd2": "~2.0.3",
    "@types/leaflet": "^1.2.7",
    "@types/lodash": "^4.14.109",
    "@types/node": "^13.7.1",
    "@types/request": "^2.47.0",
    "@types/request-promise": "^4.1.41",
    "codelyzer": "^5.2.1",
    "concurrently": "^3.5.1",
    "del-cli": "^1.1.0",
    "jasmine-core": "^3.5.0",
    "jasmine-spec-reporter": "^4.2.1",
    "karma": "^4.4.1",
    "karma-chrome-launcher": "^3.1.0",
    "karma-cli": "^2.0.0",
    "karma-coverage-istanbul-reporter": "~1.4.2",
    "karma-jasmine": "^3.1.1",
    "karma-jasmine-html-reporter": "^1.5.2",
    "protractor": "^5.4.3",
    "puppeteer": "^2.0.0",
    "rxjs-tslint": "^0.1.7",
    "ts-node": "~5.0.1",
    "tslint": "^6.0.0",
    "typescript": "3.6.4",
    "webpack": "^4.41.6"
  },
  "peerDependencies": {
    "typescript": "3.6.4",
    "tslib": "1.10.0"
  },

我得到的错误本身:

enter image description here

我已经清除了 node_modules package-lock.json 并再次运行了 npm install

编辑:也许还很重要,要注意它是使用ng serve编译和运行的,但是当我尝试构建它或使用AOT ng serve -aot运行时,我得到了错误。

4 个答案:

答案 0 :(得分:2)

我通过删除node_modules文件夹然后运行Scanner::nextLine来解决此问题。

答案 1 :(得分:1)

我今天也遇到了同样的问题,这是我如何解决此问题的方法。

可能与您无关,但错误完全相同,因此请在此处进行记录。

我正在使用Linux,如果您对项目文件夹的权限不足,则会发生此错误。

sudo chmod -R 777 <folder>

一旦我给了足够的权限,一切都会很顺利,并且运行得很好。

这是我遇到的错误的屏幕截图:

enter image description here

答案 2 :(得分:0)

我通过在项目的根目录上执行以下命令来修复此问题:

npx ngcc && ngcc -s dist

答案 3 :(得分:0)

在我的Angular项目(ng-version =“ 10.1.6”)中安装ngx-printhttps://www.npmjs.com/package/ngx-print)后出现以下错误-

:编译成功。

node_modules / ngx-print / lib / ngx-print.module.d.ts中的错误:1:22-错误NG6002:出现在AppModule的NgModule.imports中,但无法解析为NgModule类。 / h2>

这可能意味着声明NgxPrintModule的库(ngx-print)未被ngcc正确处理,或者与Angular Ivy不兼容。检查是否有较新版本的库,如果有,则进行更新。还可以考虑与该库的作者进行检查,以查看该库是否与Ivy兼容。

1个导出声明类NgxPrintModule {

解决方案- 我通过删除node_modules文件夹和package-lock.json然后运行npm install来解决此问题。