Angular 6: Module not found error regarding RxJs

aasim bairagdar

I am using

  • Angular CLI: 6.0.5
  • Node: 8.11.1
  • Angular: 6.0.3
  • rxjs: 6.2.0

when Compiling the Angular 6 app I got errors, below is just the first one

ERROR in ./src/app/web.service.ts
Module not found: Error: Can't resolve 'rxjs/add/operator/toPromise' in 

My web.service.ts code

import { Http, Headers, Response } from '@angular/http';
import 'rxjs/add/operator/toPromise';

export class WebService{
    constructor(private http:Http){

        return this.http.get("http://localhost:2000/messages").toPromise(); 

My app.module.ts code

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
import {MatButtonModule,
  MatInputModule} from '@angular/material';

import { AppComponent } from './app.component';
import { WebService } from './web.service';
import { MessagesComponent } from './messages.component';
import {HttpModule} from '@angular/http';

  declarations: [
    AppComponent,  MessagesComponent
  imports: [
    BrowserModule, HttpModule, NoopAnimationsModule, MatButtonModule, MatCardModule, MatSnackBarModule, MatToolbarModule, MatInputModule
  providers: [WebService],
  bootstrap: [AppComponent]
export class AppModule { }

I am learning Angular from video tutorial. I follow each and every step. but I got the error.


You are using HttpModule which is deprecated you should use HttpClientModule instead

it's recommended to use Observables over promises. By converting to a promise you will lose the ability to cancel a request and the ability to chain RxJS operators.
Before you can use the HttpClient, you need to import the Angular HttpClientModule into root Module.

    import { NgModule }         from '@angular/core';
    import { BrowserModule }    from '@angular/platform-browser';
    import { HttpClientModule } from '@angular/common/http';

      imports: [

Modified Code:

import { HttpClient} from '@angular/http';
import {Observable} from 'rxjs';    

    export class WebService{
        constructor(private httpc:Http){}
            return this.httpc.get("http://localhost:2000/messages"); 

Regarding the error you are getting

As of rxjs 5.5.0-beta.5+ the toPromise method is now a permanent method of Observable. You don't need to import it anymore Reference

Since You are working with RXJS 6+ I would Recommend you to go through the Changes


Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at


Login to comment


Angular 4: Module not found error regarding RxJs

Angular 6 setTimeout Module not found: Error: Can't resolve 'timers'

Angular 6 - Module not found: Error: Can't resolve 'http' in

ERROR in "path" Module not found: Error: Can't resolve - Angular 6 Webpack

error about angular2-jwt, Cannot find module 'rxjs-compat/Observable (this module not works in Angular 6)

Update to Angular v6 - Module not found: Error: Can't resolve 'fs'

Importing jquery in Angular6 : Module not found: Error: Can't resolve 'jquery'

Module not found: Error: Can't resolve 'rxjs/add/observable/throw'

Need to fix error not found in module - Angular

Error regarding angular directives

Angular 6 : where getting error module "rxjs/add/operator/map" and another error 'map' does not exist on type 'Observable<Response>'

Angular 6 and AngularFire2 RxJS Error

Why image not found error come in angular 6?

'not found' error with proxy config in Angular 6

Error: Module not found: Error: Can't resolve '@angular/cdk/scrolling'

How to keep observable alive after error in RxJS 6 and Angular 6

Angular 6 / RxJs 6 Observable merging that also skips to error block

Angular 2 - Module not found: Error: Can't resolve '@angular/material'

Error: Cannot find module "rxjs/operators" in Ionic Angular

Angular 8 - Module not found: Error: Can't resolve 'fs' in

Module not found: Error: Can't resolve '@angular/core'

Angular 2: Module not found: Error: Can't resolve

Module not found: Error: Can't resolve '@angular/animations'

Angular: Getting a module not found error only when building for prod

Angular 8 Animations Error on Lazy Loaded Module - Found Synthetic Property

Module not found error with vis-timeline and angular 8

Module not found Error : Can't resolve './ ' in Angular8

Gulp error (module not found)

module error not found on react

TOP Ranking

  1. 1

    What exactly is memory mapped io and port based io

  2. 2

    How i extract text from a model dialog in selenium?

  3. 3 port in URL

  4. 4

    Selenium browsing with headless isn't working?

  5. 5

    change TabView indicator SwiftUI

  6. 6

    python requests How to send data to a website

  7. 7

    Kubernetes pods not starting, running behind a proxy

  8. 8

    Scaffold-DbContext returns System.ArgumentNullException: Parameter name: proposedIdentifier in EFCore 2.0 when trying to pluralize

  9. 9

    Java POI: How to find an Excel cell with a string value and get its position (row) to use that position to find another cell

  10. 10

    Creating interaction sessions based on timestamps in pandas

  11. 11

    Maven annotation processing processor not found

  12. 12

    Missing field when deserializing using Jackson (Polymorphic)

  13. 13

    Spring Data JPA repository methods don't recognize property names with underscores

  14. 14

    Get all Woocommerce products from current product category term Id in a WP_Query

  15. 15

    How to update if key exists - sequelize

  16. 16

    I got message for error_log file "The stream or file ".../laravel.log" could not be opened: failed to open stream: Permission denied"

  17. 17

    Servlet: HTTP Status 404 - Not Found

  18. 18

    Type 'Moment' is not assignable to type 'Date'. Property 'toDateString' is missing in type 'Moment'

  19. 19

    what is key in CTTelephonyNetworkInfo().serviceSubscriberCellularProviders and CTTelephonyNetworkInfo().serviceCurrentRadioAccessTechnology

  20. 20

    Laravel(ajax) 404 not found

  21. 21

    Error: Cannot write a value to a ko.computed unless you specify a 'write' option. If you wish to read the current value, don't pass any parameters