user6604655
user6604655

Reputation: 1043

cannot find module '@angular/http'?

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.

Upvotes: 55

Views: 152817

Answers (16)

loay Afaneh
loay Afaneh

Reputation: 1

npm install @angular/[email protected]

version 2.1.2 is required

Upvotes: 0

Rohit Bagjani
Rohit Bagjani

Reputation: 1314

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.

Upvotes: 127

Akib Sayyed
Akib Sayyed

Reputation: 99

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

instead of

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

And in app.module.ts :

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

Upvotes: 8

nipun-kavishka
nipun-kavishka

Reputation: 922

@angular/http is deprecated

try this:

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

in the constructor:

 constructor(public http: HttpClient) { }

Upvotes: 2

Shaun Emslie
Shaun Emslie

Reputation: 21

@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';

Upvotes: 2

Mohamed A M-Hassan
Mohamed A M-Hassan

Reputation: 443

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

Upvotes: 2

Jm Paunlagui
Jm Paunlagui

Reputation: 21

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

Upvotes: 2

Amila Weerasinghe
Amila Weerasinghe

Reputation: 859

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

Upvotes: 8

Chetan Pardhi
Chetan Pardhi

Reputation: 51

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

npm install @angular/http@latest

Upvotes: 5

Sandeep Shinde
Sandeep Shinde

Reputation: 31

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

Upvotes: 3

Dip
Dip

Reputation: 696

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

Upvotes: 3

Seda Hayrapetyan
Seda Hayrapetyan

Reputation: 354

You can try to install by running below command

npm i @angular/http

Upvotes: 2

Dev Gaud
Dev Gaud

Reputation: 844

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

Upvotes: 32

Mayur Saner
Mayur Saner

Reputation: 462

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

Upvotes: 7

tony2tones
tony2tones

Reputation: 1670

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.

Upvotes: 8

Sanket
Sanket

Reputation: 20017

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.

Upvotes: 0

Related Questions