Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Unexpected value 'HttpClient' imported by the module 'AppModule'. Please add a @NgModule annotation

I do not understand why I am getting this error:

Error: Unexpected value 'HttpClient' imported by the module 'AppModule'. Please add a @NgModule annotation.

I have tried both:

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

and

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

This is the full error:

Error: Unexpected value 'HttpClient' imported by the module 'AppModule'. Please add a @NgModule annotation.
at syntaxError (http://localhost:8100/build/vendor.js:116430:34)
at http://localhost:8100/build/vendor.js:131184:44
at Array.forEach (<anonymous>)
at CompileMetadataResolver.getNgModuleMetadata (http://localhost:8100/build/vendor.js:131159:49)
at JitCompiler._loadModules (http://localhost:8100/build/vendor.js:150357:87)
at JitCompiler._compileModuleAndComponents (http://localhost:8100/build/vendor.js:150318:36)
at JitCompiler.compileModuleAsync (http://localhost:8100/build/vendor.js:150212:37)
at CompilerImpl.compileModuleAsync (http://localhost:8100/build/vendor.js:115251:49)
at PlatformRef.bootstrapModule (http://localhost:8100/build/vendor.js:5952:25)
at Object.491 (http://localhost:8100/build/main.js:2405:109)

Ionic Framework: 3.9.2 Ionic Native: ^2.9.0 Ionic App Scripts: 3.2.4 Angular Core: 5.2.11 Angular Compiler CLI: 5.2.11 Node: 8.10.0 OS: Windows 10

like image 206
DomP87 Avatar asked Apr 24 '26 01:04

DomP87


1 Answers

You need import HttpClientModule, example:

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

 @NgModule({
   imports: [
     BrowserModule,
     // import HttpClientModule after BrowserModule.
     HttpClientModule,
  ],
  declarations: [
     AppComponent,
  ],
  bootstrap: [ AppComponent ]
})

export class AppModule {}

Read: Angula HttpClient

like image 87
Ever Zevallos Avatar answered Apr 26 '26 17:04

Ever Zevallos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!