angular: Error after updated to version 9

Trying to update to version 9.

Cryptic errors and massive headache as usual 😱.

I’m stuck on this one:

ERROR in node_modules/@angular/common/http/http.d.ts:2801:22 - error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class.

This likely means that the library (@angular/common/http) which declares HttpClientModule 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.

What does it mean?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 16
  • Comments: 70 (23 by maintainers)

Commits related to this issue

Most upvoted comments

This topic has been discussed lots of times… npm ci should help you.

Setting "enableIvy": false in tsconfig.json does fix that particular error. Isn’t Ivy supposed to be usable already?

I got the same problem, I just noticed that I’ve imported MatDialog to my module instead of MatDialogModule! So ashamed about this!

Was it documented anywhere? I dont see anything in the ng 9 migration instructions

npm ci to delete node_modules and the npm install, it works for me. i had problem with Angular Materials!

We use Angular CLI. No custom build pipeling, precisely because we wanted to avoid this kind of cryptic errors and upgrade pains…

Ah brilliant @petebacondarwin it does work if we add "baseUrl": "./src" to the root tsconfig.json! That’s great, I think we’re all set to upgrade to ng9!

Thank you both for your help.

@clement911 Bingo! I can reproduce (on OS X), although the initial ng build was successful. Looking into it.

The same error repeats multiple time. Note that we did update material to 9.1.2 as part of the update instructions already.

ERROR in node_modules/@angular/common/http/http.d.ts:2801:22 - error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class.

This likely means that the library (@angular/common/http) which declares HttpClientModule 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.

2801 export declare class HttpClientModule {
                          ~~~~~~~~~~~~~~~~
node_modules/mydatepicker/dist/my-date-picker.module.d.ts:1:22 - error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class.

This likely means that the library (mydatepicker) which declares MyDatePickerModule 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.

1 export declare class MyDatePickerModule {
                       ~~~~~~~~~~~~~~~~~~
node_modules/@angular/platform-browser/animations/animations.d.ts:37:22 - error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class.

This likely means that the library (@angular/platform-browser/animations) which declares BrowserAnimationsModule 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.

37 export declare class BrowserAnimationsModule {
                        ~~~~~~~~~~~~~~~~~~~~~~~
node_modules/@angular/material/dialog/dialog-module.d.ts:8:22 - error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class.

This likely means that the library (@angular/material/dialog) which declares MatDialogModule 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.

8 export declare class MatDialogModule {
                       ~~~~~~~~~~~~~~~
node_modules/@angular/material/input/input-module.d.ts:8:22 - error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class.

This likely means that the library (@angular/material/input) which declares MatInputModule 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.

8 export declare class MatInputModule {
                       ~~~~~~~~~~~~~~
node_modules/@angular/material/select/select-module.d.ts:8:22 - error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class.

This likely means that the library (@angular/material/select) which declares MatSelectModule 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.

8 export declare class MatSelectModule {
                       ~~~~~~~~~~~~~~~
node_modules/@angular/material/checkbox/checkbox-module.d.ts:11:22 - error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class.

This likely means that the library (@angular/material/checkbox) which declares MatCheckboxModule 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.

11 export declare class MatCheckboxModule {
                        ~~~~~~~~~~~~~~~~~
node_modules/@angular/material/form-field/form-field-module.d.ts:8:22 - error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class.

This likely means that the library (@angular/material/form-field) which declares MatFormFieldModule 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.

8 export declare class MatFormFieldModule {
                       ~~~~~~~~~~~~~~~~~~
node_modules/@angular/material/snack-bar/snack-bar-module.d.ts:8:22 - error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class.

This likely means that the library (@angular/material/snack-bar) which declares MatSnackBarModule 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.

8 export declare class MatSnackBarModule {
                       ~~~~~~~~~~~~~~~~~
node_modules/@angular/material/icon/icon-module.d.ts:8:22 - error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class.

This likely means that the library (@angular/material/icon) which declares MatIconModule 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.

8 export declare class MatIconModule {
                       ~~~~~~~~~~~~~
node_modules/@angular/material/tree/tree-module.d.ts:8:22 - error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class.

This likely means that the library (@angular/material/tree) which declares MatTreeModule 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.

8 export declare class MatTreeModule {
                       ~~~~~~~~~~~~~
node_modules/@angular/material/tooltip/tooltip-module.d.ts:8:22 - error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class.

This likely means that the library (@angular/material/tooltip) which declares MatTooltipModule 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.

8 export declare class MatTooltipModule {
                       ~~~~~~~~~~~~~~~~
node_modules/@angular/material/slider/slider-module.d.ts:8:22 - error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class.

This likely means that the library (@angular/material/slider) which declares MatSliderModule 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.

8 export declare class MatSliderModule {
                       ~~~~~~~~~~~~~~~

@mhmdtshref Good catch man, spent an hour troubleshooting that and the error got solved by actually importing the module. Who would have thought? 🙃 Thanks a lot!

I just had this issue when importing angular material radio. I just stopped the running console and try again with ng serve.

Same situation for me when importing material slider.

This is a very common requirement - we use it in the Angular repo. See https://github.com/angular/angular/blob/master/packages/tsconfig.json#L18-L24.

Normally you combine the baseUrl with a paths configuration as seen above. I think the key for your IDE to pick it up is for it to be in a plain tsconfig.json, rather than tsconfig.app.json which the IDE does not know about.

So the issue here is definitely with the src/node_modules directory. I have no idea why that thing is there, but it is considered as primary node_modules directory and this causes all ngcc’s path computations to be off, leading to all sorts of issues with incorrect paths when writing compiled artifacts.

I’m attempting to prepare a minimal repro.

I got this in a brand new app ng new …

  ERROR in node_modules/@angular/common/http/http.d.ts:2801:22 - error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class.
    
    This likely means that the library (@angular/common/http) which declares HttpClientModule 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.
    
    2801 export declare class HttpClientModule {

I asked about ng serve because I have seen some cases where the change to the node_modules is not picked up by a running build. By restarting it should clear and cache. Clearing node_modules is also often effective, since it will completely invalidate all dependencies - there are sometime caching issues with yarn/npm too.

@petebacondarwin So I have to stop ng serve before installing or updating packages?

In my case removing node_modules and reinstalling them solve the issue

@clement911 Now that could be a Windows-only caching issue as I mentioned yesterday, but I’m only guessing at this point. There was a general caching issue with the CLI regarding declaration files that was fixed in https://github.com/angular/angular-cli/pull/16992.

As a workaround, you should be able to run ngcc manually on postinstall, so that the CLI won’t have to process anything. Details can be found in the documentation.