我试图在假json服务器上用crud构建一个简单的应用程序

我不能输入HttpClientModule

下面是来自VS Code的错误消息:

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 {

这是app.module.ts美元

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { EmployeeCreateComponent } from './employee-create/employee-create.component';
import { EmployeeEditComponent } from './employee-edit/employee-edit.component';
import { EmployeeListComponent } from './employee-list/employee-list.component';

import { HttpClientModule } from '@angular/common/http';


@NgModule({
  declarations: [
    AppComponent,
    EmployeeCreateComponent,
    EmployeeEditComponent,
    EmployeeListComponent
  ],
  imports: [
    BrowserModule,
    HttpClientModule,
    AppRoutingModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

app.component.ts

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'restTest6';
}

注意:我没有在其他地方使用HttpClientModule.我输入了ng serve -o个,结果出错了.请指出哪里出了问题

推荐答案

我也遇到了同样的问题,我只是运行了下面的命令,之后它就正常工作了,没有任何错误.

npm cache verify

如果没有,请try 手动删除node_modules文件夹,然后用npm install重新安装模块.

rm -rf node_modules
npm install

关于npm>;6、你也可以运行npm ci,这也会删除node_modules文件夹,然后重新安装软件包.

Edit正如其他答案所建议的,如果上述步骤不起作用(但它们通常起作用),您可能需要重新启动ng serve

Typescript相关问答推荐

无需刷新即可让现场访客逆变

TypeScript类型不匹配:在返回类型中处理已经声明的Promise Wrapper

扩展函数签名中的参数类型,而不使用泛型

Redux—Toolkit查询仅在不为空的情况下添加参数

如何设置绝对路径和相对路径的类型?

Angular 错误NG0303在Angular 项目中使用app.Component.html中的NGFor

使用2个泛型类型参数透明地处理函数中的联合类型

嵌套对象的类型

在HighChats列时间序列图中,十字准线未按预期工作

使用KeyOf和Never的循环引用

推断从其他类型派生的类型

剧作家元素发现,但继续显示为隐藏

在正常函数内部调用异步函数

如何编辑切片器以使用CRUD调用函数?

使用或属性编写无限嵌套的接口

Typescript,如何在通过属性存在过滤后重新分配类型?

使用强类型元组实现[Symbol.iterator]的类型脚本?

打字脚本错误:`不扩展[Type]`,而不是直接使用`[Type]`

无法使用prisma中的事务更新记录

在对象类型的类型别名中,属性是用分号 (;) 还是逗号 (,) 分隔的?