简体   繁体   中英

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.

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.

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

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.

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

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
import { HttpClient } from '@angular/common/http';

instead of

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

And in app.module.ts :

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

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

npm install @angular/http@latest

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

use this command for instaling http modules

您可以尝试通过运行以下命令来安装

npm i @angular/http

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

@angular/http is deprecated

try this:

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

in the constructor:

 constructor(public http: HttpClient) { }

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

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

CDN path is - https://npmcdn.com/@angular/http@2.0.0-rc.4/

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.

npm install @angular/http@2.1.2

需要 2.1.2 版本

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM