21

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

2801 export declare class HttpClientModule {
Kapil
  • 231
  • 1
  • 2
  • 5
  • 1
    your question is like on [enter link description here](https://stackoverflow.com/questions/60290309/error-ng6002-appears-in-the-ngmodule-imports-of-appmodule-but-could-not-be-res) – Arbahud Rio Daroyni Mar 03 '20 at 13:45

14 Answers14

20

restart your server...

terminate server for windows

ctrl + C

start again

ng serve
Shuvo
  • 357
  • 2
  • 7
14

I had the same issue.
I was going through comments here https://github.com/angular/angular/issues/35399 for solution.

I simple ran ng serve --prodand the error was gone. After that I even ran ng serve.
Other solutions proposed are

  • Ensure that the tsconfig.json of your library has set "importHelpers": true
  • Add "enableIvy": false to compilerOptions in tsconfig.app.json
lokesh kumar
  • 961
  • 1
  • 10
  • 18
  • After updating my app from Angular 9 -> 10 -> 11, I received the NG6002 error for package "ngx-lightbox" when attempting `ng build` or `ng serve`. Running `ng serve --prod` did solve the issue for me, but can anyone explain why? The GitHub issue linked above has a few comments indicating "This worked for me" but I didn't see any explanation. – mfcallahan Dec 15 '20 at 21:02
10

Adding "postinstall": "ngcc" to scripts: {...} in package.json then run npm run postinstall solved problem.

if you still want to keep the Anuglar Ivy and AOT advantage

Hiep Tran
  • 3,735
  • 1
  • 21
  • 29
9

Simply restart the server (press ctrl+c on the prompt) and then, run ng serve again.

I had the same issue. Then I realized that previously I've some changes in app.module.ts Every time you made changes in app.module.ts remember restart the server process.

Ulisses Souza
  • 111
  • 1
  • 5
6

I had the same issue. I was adding service to module i.e. app.module.ts's imports array instead of adding it to the providers array.

app.module.ts

@NgModule({
  imports: [
    MyService // wrong here
  ],
  providers: [
    MyService // should add here
  ]
})
export class EventsModule { }
WasiF
  • 26,101
  • 16
  • 120
  • 128
4

For me I had a Pipe declared in my 'imports' in my module. Apparently many things can produce this error. I do not suggest you disable IVY, as that is not the problem.

Jonathan
  • 3,893
  • 5
  • 46
  • 77
4

Setting "aot": false inside angular.json file worked for me.

Rachana Kotha
  • 159
  • 1
  • 6
2

I terminated the current build and restarted it again. i.e ng serve solved my error. Hope it helps.

Ivan Aracki
  • 4,861
  • 11
  • 59
  • 73
1

In my case, I had included HttpClientModule run running the Angular server. The below solution works best for my case

Just Close the Server, and reopen it. It will work.

Syed Umer Hasan
  • 644
  • 7
  • 11
0

Working within an NX workspace I just came across this issue.

After a lot of searching I realised that the internal library that I just created had by default Ivy turned off.

I do have it on everywhere else. And yes, even for my libraries. They're only internal to the monorepo we don't expose any of them so we don't want to have an extra step to compile them with the deprecated view engine instructions and later on run ngcc onto it to turn that into Ivy code.

Conclusion: I just forgot to set

  "angularCompilerOptions": {
    "enableIvy": true
  }

on my newly created library and the default is false which wasn't working in my case.

maxime1992
  • 22,502
  • 10
  • 80
  • 121
0

I had same issue in ubuntu. But when I used sudo bash command and executed ng serve. It resolve the issue

0

I had the same problem, it seems like there is a lot of ways to trigger the problem. I recommend trying to verify the .component, .module and the app.module declarations. Mine was triggered because I've declared the .component in app.module instead of the .module.

ouflak
  • 2,458
  • 10
  • 44
  • 49
0

This happened to me in VSCode with another module after installing it with npm install. This is most likely related to how the Angular language service extension works and the quickest way to solve it was to restart the IDE.

Alexei - check Codidact
  • 22,016
  • 16
  • 145
  • 164
0

this problem caused by angular extension and snippets in vscode be careful not to install obsolete extensions like Angular Extension Pack and Angular Language Service enter image description here