Error TS2307: Cannot find module '@ angular / common / http' for HttpClientModule

I am trying to import an HttpClientModule using the following line in my .module.ts application:

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

and

imports: [ ... HttpClientModule, ... ] 

However, I keep getting the same error:

src / app / app.module.ts (4,38): TS2307 error: cannot find module '@ angular / common / http'.

Although these exact lines are included in these tutorials:

How can I fix this and use HttpClient?

+5
source share
1 answer

A new http client was added only in version 4.3 . You are probably using an older version of angular. You need to update the project. Go to package.json and change all @angular/... entries to enable version ^4.3.4 .

In addition, if you are 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 the difference between HTTP and HTTPClient in angular 4?

+13
source

Source: https://habr.com/ru/post/1270881/


All Articles