简体   繁体   English

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

[英]error NG6002: Appears in the NgModule.imports of <module>, but could not be resolved to an NgModule class

I just updated from Angular 8.2 to 9.我刚刚从 Angular 8.2 更新到 9。

Everything works well if I disable ivy, but when it's enabled I'm getting a lot of errors that seems to be kind of obscure, at least I can't find any results when googling it.如果我禁用常春藤,一切都会很好,但是当它启用时,我会遇到很多似乎有点模糊的错误,至少我在谷歌搜索时找不到任何结果。

I'm quite sure I've done everything needed for an update, ie changed the lazyloading to use dynamic imports and fixed Angular Material import paths etc.我很确定我已经完成了更新所需的一切,即将延迟加载更改为使用动态导入和固定 Angular Material 导入路径等。

I will also include my package.json dependencies here我还将在此处包含我的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"
  },

And errors itself that I'm getting:我得到的错误本身是:

在此处输入图像描述

I have cleared my node_modules and package-lock.json and ran npm install again我已经清除了我的node_modulespackage-lock.json并再次运行npm install

EDIT : maybe also important to note that it's compiling and running with ng serve but when I try to build it or run with AOT ng serve -aot then I get the errors.编辑:也许同样重要的是要注意它正在使用ng serve编译和运行,但是当我尝试构建它或使用 AOT ng serve -aot运行时,我得到了错误。

我通过删除 node_modules 文件夹来解决这个问题,然后运行npm install

I faced the same issue today and here is how I resolved it in my scenario.我今天遇到了同样的问题,这是我在我的场景中解决它的方法。

Might not be relevant to you but the error is exactly same, hence documenting here.可能与您无关,但错误完全相同,因此在此处记录。

I was using Linux and this error occurs if you don't have enough permissions on the project folder.我使用的是 Linux,如果您对项目文件夹没有足够的权限,则会出现此错误。

sudo chmod -R 777 <folder>

Once I gave enough permissions, everything was smooth and just runs fine.一旦我给予足够的权限,一切都很顺利并且运行良好。

Here is the screenshot of the error that I was getting:这是我收到的错误的屏幕截图:

在此处输入图片说明

我通过在项目的根目录上执行这个命令来解决这个问题:

npx ngcc && ngcc -s dist

Getting below error after installing ngx-print ( https://www.npmjs.com/package/ngx-print ) in my Angular project (ng-version="10.1.6") -在我的 Angular 项目 (ng-version="10.1.6") 中安装ngx-print ( https://www.npmjs.com/package/ngx-print ) 后出现以下错误 -

: Compiled successfully. : 编译成功。

ERROR in node_modules/ngx-print/lib/ngx-print.module.d.ts:1:22 - error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class. node_modules/ngx-print/lib/ngx-print.module.d.ts:1:22 中的错误 - 错误 NG6002:出现在 AppModule 的 NgModule.imports 中,但无法解析为 NgModule 类。

This likely means that the library (ngx-print) which declares NgxPrintModule has not been processed correctly by ngcc, or is not compatible with Angular Ivy.这可能意味着声明 NgxPrintModule 的库 (ngx-print) 没有被 ngcc 正确处理,或者与 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.还可以考虑与库的作者核对以查看该库是否与 Ivy 兼容。

1 export declare class NgxPrintModule { 1 导出声明类 NgxPrintModule {

Solution - I fix this problem with removing the node_modules folder and package-lock.json and then run npm install .解决方案 -我通过删除node_modules文件夹和package-lock.json解决这个问题,然后运行npm install

I had been searching for the answer to this question, as I was frustrated from looking into answers that did not help, while I gave up on the internet I tried to look into the dist folder of the build (library) and what is changed, the first thing to noticed was the ive_ngcc_ folder added, which means that it was still processing the build as ivy and not the regular even though I had set the enable ivy : false in my library project.我一直在寻找这个问题的答案,因为我对寻找没有帮助的答案感到沮丧,而我在互联网上放弃了我试图查看构建(库)的 dist 文件夹以及发生了什么变化,首先要注意的是添加了 ive_ngcc_ 文件夹,这意味着即使我在我的库项目中设置了 enable ivy : false ,它仍在将构建处理为 ivy 而不是常规。 sometimes it happens in angular version 9有时它发生在 Angular 版本 9 中

Fix steps:修复步骤:

  1. remove node modules folder (library project) used command on windows ( rm .\\node_modules)删除节点模块文件夹(库项目)在 Windows 上使用的命令( rm .\\node_modules)
  2. remove existing dist folder used command (rm .\\dist)删除现有的 dist 文件夹使用的命令 (rm .\\dist)
  3. remove the package-lock.json file删除 package-lock.json 文件
  4. run npm cache clean --force运行 npm cache clean --force
  5. just in case I wasn't sure if this would work I ran npm restart (I think this step did the trick)以防万一我不确定这是否可行,我运行 npm restart (我认为这一步成功了)
  6. ran npm install运行 npm 安装
  7. ran npm build (in tsconfig > angularCompilerOptions > enableIVY: false)运行 npm build (在 tsconfig > angularCompilerOptions > enableIVY: false)
  8. most important recheck dist folder to see if ivy_ngcc folder not present最重要的是重新检查 dist 文件夹以查看 ivy_ngcc 文件夹是否不存在
  9. use npm link or publish beta and use it in parent app (now it should work) !!使用 npm 链接或发布 beta 并在父应用程序中使用它(现在它应该可以工作)!

key take away the error is misleading as there could be whole host of problems that could raise this same error, my use case was using custom library created for our project.关键带走该错误具有误导性,因为可能存在许多可能引发相同错误的问题,我的用例是使用为我们的项目创建的自定义库。 hope this helps some devs out there and save their time !!希望这可以帮助一些开发人员并节省他们的时间! Happy Coding !!快乐编码!

Environment Details: Win OS 10 npm : 6.14.3 node : 14.17.2 angular:: 9.1.3环境详细信息:Win OS 10 npm:6.14.3 节点:14.17.2 angular:: 9.1.3

Error: projects/paidia/src/app/shared/modules/shared.module.ts:141:14 - error NG6002: Appears in the NgModule.imports of TournamentModule, but itself has errors错误:projects/paidia/src/app/shared/modules/shared.module.ts:141:14 - 错误NG6002:出现在TournamentModule的NgModule.imports中,但本身有错误

141 export class SharedModule { ~~~~~~~~~~~~ 141 导出类 SharedModule { ~~~~~~~~~~~~

Error: projects/paidia/src/app/shared/modules/shared.module.ts:141:14 - error NG6002: Appears in the NgModule.imports of VideosModule, but itself has错误:projects/paidia/src/app/shared/modules/shared.module.ts:141:14 - 错误NG6002:出现在VideosModule的NgModule.imports中,但本身有

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Angular 错误NG6002:出现在AppModule的NgModule.imports中,但无法解析为NgModule class - Angular error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class 错误 NG6002:出现在 AppModule 的 NgModule.imports 中,但无法解析为 NgModule class - error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class 错误 NG6002:出现在 AppModule 的 NgModule.imports 中,但无法解析为 NgModule class。 是否缺少@NgModule 注释? - error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class. Is it missing an @NgModule annotation? Angular 12 迁移问题错误 NG6002:出现在 AppModule 的 NgModule.imports 中,但本身有错误 - Angular 12 migration issue error NG6002: Appears in the NgModule.imports of AppModule, but itself has errors 错误:出现在 AppModule 的 NgModule.imports 中,但无法解析为 NgModule class - error : Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class 错误NG6002:出现在AppModule的NgModule.imports中,但本身有错误AppRoutingModule - error NG6002: Appears in the NgModule.imports of AppModule, but itself has errors AppRoutingModule error NG6002:出现在AppModule的NgModule.imports中,但本身有错误 - error NG6002: Appears in the NgModule.imports of AppModule, but itself has errors Angular更新8到9:NG6002:出现在AppModule的NgModule.imports中,但本身有错误 - Angular update 8 to 9: NG6002: Appears in the NgModule.imports of AppModule, but itself has errors 出现在 AppModule 的 NgModule.imports 中,但无法解析为 NgModule 类 - Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class 出现在 ProductsModule 的 NgModule.imports 中,但无法解析为 NgModule 类 - Appears in the NgModule.imports of ProductsModule, but could not be resolved to an NgModule class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM