角度:HttpClientModule导入错误(无法解析为NgModule类)

用户名

我试图在伪造的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

如果不是,请尝试手动删除node_modules文件夹,然后使用重新安装模块npm install

rm -rf node_modules
npm install

在npm> 6上,您还可以运行npm ci,它还会删除node_modules文件夹并在之后重新安装软件包。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

错误NG6002:出现在AppModule的NgModule.imports中,但无法解析为NgModule类

Angular 错误 NG6002:出现在 AppModule 的 NgModule.imports 中,但无法解析为 NgModule 类

错误 NG6002:出现在 AppModule 的 NgModule.imports 中,但无法解析为 NgModule 类。它是否缺少@NgModule 注释?

我导入的任何类都无法解析为jsp文件中的类型,错误为500

出现在AppModule的NgModule.imports中,但无法解析为angular 8中的NgModule类

Eclipse 错误:“导入...无法解析”

导入错误:无法导入名称和无法导入类

类无法解析为类型

Angular Tour of Heroes错误导入HttpClientModule

AndroidStudio无法解析导入库中的类

导入的方法无法解析为方法

相对导入无法解析为环境模块

导入后Eclipse无法解析为类型

角度 错误:组件NewPharmacyComponent不属于任何NgModule或模块尚未导入到模块中

ImportXML错误:无法解析导入的XML内容

Eclipse错误:“导入XXX无法解析”

将Java类导入到jsp导致无法解决为类型错误

角度-错误:无法解析“ classlist.js”

无法为nltk导入名称defaultdict错误

尝试实施Google Analytics(分析)时,错误跟踪器类无法解析为变量

Java 使用 if(search) == 和多个类给出错误搜索无法解析为变量

Java类“无法解析为类型”

包/类无法解析为类型

类无法解析为类型(jsp)

导入错误:无法为 slackclient 导入名称 parse_url

Maven无法解析Mojo的配置-错误的类

JSON解析错误:无法构造类的实例

如何解决错误组件不是任何NgModule的一部分或未正确导入角度6中?

角度错误:请添加@NgModule批注