[英]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_modules和package-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:修复步骤:
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.