1

When I try to do ng build , I get an error saying

ERROR in node_modules/@angular/common/http/http.d.ts:81: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 HttpClient 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.

81 export declare class HttpClient {

I try to delete the node_modules and reinstall it by ng install. I have even tried npm ci since I saw that as a solution at some other blog post, but none worked for me.

Here's my output for ng version

Angular CLI: 10.1.2
Node: 14.11.0
OS: darwin x64

Angular: 10.1.2
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Ivy Workspace: Yes

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1001.2
@angular-devkit/build-angular   0.1001.2
@angular-devkit/core            10.1.2
@angular-devkit/schematics      10.1.2
@schematics/angular             10.1.2
@schematics/update              0.1001.2
rxjs                            6.6.3
typescript                      4.0.3

My AppModule looks like this

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import {HttpClientModule} from '@angular/common/http'
import {HttpClient} from '@angular/common/http'

import { AppComponent } from './app.component';
import { SocketService } from "./socket.service";

@NgModule({
    declarations: [
        AppComponent
    ],
    imports: [
        BrowserModule,
        FormsModule,
        HttpClient,
        HttpClientModule
    ],
    providers: [SocketService],
    bootstrap: [AppComponent]
})
export class AppModule { }

Rajat Singh
  • 653
  • 6
  • 15
  • 29

1 Answers1

5

the HttpClient is a service, not a module to be imported, remove that from your imports array.

imports: [
    BrowserModule,
    FormsModule,
    HttpClientModule
],
bryan60
  • 28,215
  • 4
  • 48
  • 65