55

I added the following property to my systemjs.config.js map object in my Angular 2 app:

'@angular/http': 'https://npmcdn.com/@angular/http'

When I ctrl-click on the url it attempts to download a js file. However, when I try to import from '@angular/http' at the top of my service.ts, the compiler returns the error "Cannot find module '@angular/http'.`"

Is there an additional step that I'm missing in order for this module to be recognized and usable by my angular app? I'm using Angular version 2.0.0-rc.4.

3
  • Can you share your systemjs.config.js? Commented Jul 21, 2016 at 17:13
  • I put systemjs.config.js in this plunk: plnkr.co/edit/mGCDGuYmyzv1ykJl7HtY?p=catalogue Commented Jul 21, 2016 at 17:17
  • There are no errors. Even I don't see any service.ts Commented Jul 21, 2016 at 17:23

16 Answers 16

127

run this in terminal:

npm install @angular/http@latest

Update for Angular 5+ versions:

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

instead of HttpModule and Http respectively.

Sign up to request clarification or add additional context in comments.

1 Comment

http was deprecated in Angular 5 and then removed. For Angular >= 4.3, HttpClient must be used (see @DevGaud's answer below)
32

The entire @angular/http package has been removed. Use @angular/common/http. so instead of importing this one

'@angular/http'

use this

'@angular/common/http'

for further information about other changes go to Angular- Deprecated APIs and Features

4 Comments

It worked, but also I had to change import { Http } to import { HttpClient } in Angular 8. Final syntax : import { HttpClient } from '@angular/common/http'
Yeah, they also updated the 'Http' class to 'HttpClient'. Now I think about it, my answer could have more upvotes. Anyway thanks for giving the final syntax, people might find it helpful.
Thanks, it worked but I used: import { HttpClientModule} from '@angular/common/http' since I wanted to use it in NgModule({ imports})
npm install @angular/common@latest, Use this command
8

Have you tried adding

"@angular/http": "^7.1.1",

to your package.json file? Once you do run npm install and you should be golden.

Comments

8

1.This worked for me.Try installing latest angular http

npm install @angular/http@latest

2.Also you can try use

'@angular/common/http'

instead of this

'@angular/http'

The reason for the second option is

The following APIs have been removed starting with version 8.0.0:

PACKAGE API REPLACEMENT NOTES

@angular/http

All exports replaced with

@angular/common/http

Comments

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

instead of

import { Http } from '@angular/http';

And in app.module.ts :

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

Comments

7

You need to have latest version of http. Try the following command in terminal, hope this will solve your problem...

npm install @angular/http@latest

Comments

5

I use below command & "cannot find module '@angular/http'" issue get solved.

npm install @angular/http@latest

Comments

3

Just node command prompt, go to project folder and run

npm install @angular/http@latest

If there is any severity found as sometimes it show after you install, just use

npm audit fix

Comments

3

use this command for instaling http modules
npm install @angular/http@latest

Comments

2

You can try to install by running below command

npm i @angular/http

Comments

2

Try this, it works! HttpClientModule

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

@NgModule({
  declarations: [
    AppComponent,
  ],
  imports: [
    BrowserModule,
    *HttpClientModule,*
    ReactiveFormsModule,
    AppRoutingModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

It worked in my code

Comments

2

The entire @angular/http package has been removed. Use @angular/common/http instead.

Replace HttpModule with HttpClientModule (from @angular/common/http) in each of your modules.

So you can import like: import { HttpClient } from '@angular/common/http';

for more info, read this: https://angular.io/guide/deprecations#angularhttp

Comments

2

@angular/http is deprecated.

Try:

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

refer to https://angular.io/guide/deprecations#angularhttp for more info.

If you insist on using @angular/http try:

npm install @angular/http@latest

import { Http } from '@angular/http';

Comments

2

@angular/http is deprecated

try this:

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

in the constructor:

 constructor(public http: HttpClient) { }

Comments

0

CDN path is - https://npmcdn.com/@angular/[email protected]/

By default, systemjs.config.js looks for index.js in this path.

Refer this plunker example - https://angular.io/resources/live-examples/quickstart/ts/plnkr.html

Also, make sure while importing use below syntax-

import { Http } from '@angular/http';

See if this helps.

3 Comments

I tried including the cdn path you provided for the http ref I included in my config file. I tried it with and without the trailing slash but I still got the same errors. I did a file compare between my config file and the one you provided on your plunk but the only diffs were that http was removed from your map and the routerVer minor version was different.
Here's a plunk with a full working version of a service that angular.io provides online: angular.io/resources/live-examples/server-communication/ts/… My config.js is the same as the one provided in the example plunk. Therefore, my build failure [Cannot find module '@angular/http'] does not appear to be due to gaps in my config file. I even copied/pasted the import from the example into my service.ts to account for possible typos or other weirdness. I checked the output console of the build and no additional info was returned. Any ideas for additional troubleshooting?
can you please share your complete example in plunker? so that we can look any typo or any other mistakes.
0
npm install @angular/[email protected]

version 2.1.2 is required

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.