I am trying to import HttpClientModule using the following line in my app.module.ts:
import { HttpClientModule } from '@angular/common/http';
and
imports: [
...
HttpClientModule,
...
]
However I keep getting the same error:
src/app/app.module.ts(4,38): error TS2307: Cannot find module '@angular/common/http'.
Despite those exact lines being included in these tutorials:
https://angular.io/guide/http
https://medium.com/codingthesmartway-com-blog/angular-4-3-httpclient-accessing-rest-web-services-with-angular-2305b8fd654b
http://blog.ninja-squad.com/2017/07/17/http-client-module/
How can I fix this and use HttpClient ?
The HttpClient is used to perform HTTP requests and it imported form @angular/common/http. The HttpClient is more modern and easy to use the alternative of HTTP. HttpClient is an improved replacement for Http.
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.
The new http client was only added in the 4.3
version. You're probably using older angular version. You need to update the project. Go into package.json
and modify all @angular/...
entries to include ^4.3.4
version.
Also, if you're using SystemJS you need to add two entries to the map
:
'tslib': 'npm:tslib/tslib.js',
'@angular/common/http': 'npm:@angular/common/bundles/common-http.umd.js',
Also see Difference between HTTP and HTTPClient in angular 4?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With