2

I am facing an error all of a sudden in a perfectly fine running application

Cannot find module '@angular/http'

import { Http } from '@angular/http'

I am using http to read a json file

 this.http.get('assets/env/env.json').pipe(map( res => res.json()))

Please help

3
  • try installing deps again npm i Commented Sep 21, 2020 at 13:14
  • Is the "of a sudden" an angular upgrade? Commented Sep 21, 2020 at 13:24
  • @MoxxiManagarm No mate.. I did a package installation.. Then onwards this error happens... I am new in Angular... Commented Sep 21, 2020 at 13:30

3 Answers 3

3

angular replaced the http module back in around angular 5 or 6. It's been deprecated for some time. You now need to use the HttpClient and HttpClientModule from @angular/common/http

but be aware that the Http service and the HttpClient service have some important differences that may break your app if it was using Http

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

Comments

2

Http was deprecated. Use HttpClient

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

Comments

2

@angular/http is depricated and in recent versions and is now removed from the generated package.json file, use HttpClient from '@angular/common/http'.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.