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)
Links to this issue
Commits related to this issue
- fix(ngcc): correctly identify the package of targeted entry-points In some scenarios, such as yarn workspaces, the node_modules folder containing the target entry-point is not contained by the origin... — committed to petebacondarwin/angular by petebacondarwin 4 years ago
- fix(ngcc): correctly identify the package path of secondary entry-points Previously we only searched for package paths below the set of `basePaths` that were computed from the `basePath` provided to ... — committed to petebacondarwin/angular by petebacondarwin 4 years ago
- fix(ngcc): correctly identify the package path of secondary entry-points Previously we only searched for package paths below the set of `basePaths` that were computed from the `basePath` provided to ... — committed to petebacondarwin/angular by petebacondarwin 4 years ago
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 ofMatDialogModule
! 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 thenpm 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.
@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!
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 apaths
configuration as seen above. I think the key for your IDE to pick it up is for it to be in a plaintsconfig.json
, rather thantsconfig.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 primarynode_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
…I asked about
ng serve
because I have seen some cases where the change to thenode_modules
is not picked up by a running build. By restarting it should clear and cache. Clearingnode_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.