Saturday, November 20, 2021

How to fix Angular Cannot find module ‘@angular/http’ after ‘ng update’

 When updating to Angular 8.x+, developers commonly encouter this type of error:

app/app.module.ts:9:42 - error TS2307: Cannot find module '@angular/http'.

9 import {HttpModule, RequestOptions} from '@angular/http';

The solution

The @angular/http module has been removed in recent versions of Angular and replaced by @angular/common/http.  Furthermore, there are some name changes that might need manual fixing, including:

  • HttpModule ⇒ HttpClientModule
  • Http ⇒ HttpClient
  • URLSearchParams ⇒ HttpParams

Note that the replacements are not always exact equivalent and hence might require some work to get working

See the official @angular/http deprecation guide for more details on how to migrate.

No comments:

Post a Comment

No String Argument Constructor/Factory Method to Deserialize From String Value

  In this short article, we will cover in-depth the   JsonMappingException: no String-argument constructor/factory method to deserialize fro...