无法在 Angular 10 中处理 HttpClient

Unable to process HttpClient in Angular 10

当我尝试执行 ng build 时,我收到一条错误消息

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 {

我尝试删除 node_modules 并通过 ng install 重新安装它。我什至尝试过 npm ci,因为我在其他一些博客 post 上看到这是一个解决方案,但 none 对我有用。

这是我对 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

我的 AppModule 看起来像这样

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 { }

HttpClient 是一项服务,而不是要导入的模块,请将其从您的导入数组中删除。

imports: [
    BrowserModule,
    FormsModule,
    HttpClientModule
],