Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.3K
Views
Angular: error de importación de HttpClientModule (no se pudo resolver en una clase NgModule)

Estaba tratando de crear una aplicación simple con crud en un servidor json falso

pero no puedo importar HttpClientModule

Aquí hay un mensaje de error de 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 {

Aquí está 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 { }

aplicación.componente.ts

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

tenga en cuenta que: no usé HttpClientModule en ningún otro lugar. Importé e hice ng serve -o y obtuve un error. Por favor, señale lo que salió mal

over 4 years ago · Santiago Trujillo
9 answers
Answer question

0

Tuve el mismo problema, simplemente ejecuté el siguiente comando y funcionó sin ningún error.

 npm cache verify

Si no es así, intente eliminar manualmente la carpeta node_modules y reinstalar los módulos con npm install .

 rm -rf node_modules npm install

En npm > 6, también puede ejecutar npm ci , que también elimina la carpeta node_modules y reinstala los paquetes después.

Editar Como sugirieron otras respuestas, es posible que deba reiniciar ng serve si los pasos anteriores no funcionan (pero normalmente lo hacen)

over 4 years ago · Santiago Trujillo Report

0

simplemente detenga ng serve antes de agregar un nuevo paquete, después de agregar un nuevo paquete, reinicie ng serve. Esto resolverá este problema.

over 4 years ago · Santiago Trujillo Report

0

Tuve el mismo problema. Entonces, eliminé manualmente node_modules y luego npm install . Se resolvió ya que este problema se debió a las dependencias corruptas.

over 4 years ago · Santiago Trujillo Report

0

Primero deja de servir y ejecuta estos comandos...

 npm cache verify rm -rf node_modules npm install

Después de la instalación, construya y ejecute su proyecto usando los comandos

 ng build ng serve

A mi me funciono y soluciono el problema...

over 4 years ago · Santiago Trujillo Report

0

En mi caso, cerré VS Code, volví a abrir el proyecto e hice 'ng serve'. Funcionó.

over 4 years ago · Santiago Trujillo Report

0

Puede agregar este HttpClientModule a las importaciones en app.component.ts .

 imports: [HttpClientModule]
over 4 years ago · Santiago Trujillo Report

0

En primer lugar, solo necesita eliminar la carpeta de módulos de nodo y luego actualizar el npm usando el comando

npm i -g npm

Luego, debe compilar su proyecto para el mantenimiento del proyecto angulare, que se puede realizar mediante el comando

construir

entonces podrá servir o alojar el proyecto escribiendo el comando g

ng servir

over 4 years ago · Santiago Trujillo Report

0

Resolví este problema usando los siguientes pasos

  1. detenido ng servir cmd
  2. ejecutó npm caché verificar cmd
  3. comenzó ng servir cmd
over 4 years ago · Santiago Trujillo Report

0

En mi caso, estaba haciendo algunas pruebas unitarias y agregué HttpModule en el archivo app.module.ts en la sección de importaciones. Para resolver este problema, simplemente eliminé la importación HttpModule del módulo de la aplicación y solucioné el error.

 // app.module.ts @NgModule({ declarations: [AppComponent, ...], imports: [ // Removed from here <-- ...
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!