3

In my angular app I am not able to import Observables using below command -

import { Observable } from 'rxjs/Observable';

Facing below error -

ERROR in node_modules/rxjs/Observable.d.ts(1,15): error TS2307: Cannot find module 'rxjs-compat/Observable'.
node_modules/rxjs/Rx.d.ts(1,15): error TS2307: Cannot find module 'rxjs-compat'.
src/app/home/home.component.ts(2,10): error TS2305: Module '"../../../node_modules/rxjs/Observable"' has no exported member 'Observable'

Can anyone suggest some answer ?

Selaka Nanayakkara
  • 3,296
  • 1
  • 22
  • 42
Gourav Bansal
  • 73
  • 1
  • 7
  • Does this answer your question? [Cannot find module 'rxjs-compat/Observable'](https://stackoverflow.com/questions/52388927/cannot-find-module-rxjs-compat-observable) – Lemmy Dec 25 '19 at 08:09

3 Answers3

8

You need to import as follows,

import { Observable } from 'rxjs';

This is most possibly because, you might have upgraded you angular project or rxjs library.

Plochie
  • 3,944
  • 1
  • 17
  • 33
6

According to the error it says clearly that it Cannot find module 'rxjs-compat/Observable' In order use rxjs-compat/Observable you need to install it inside the your project. In order to install

Try running below command:-

npm install --save rxjs-compat

Selaka Nanayakkara
  • 3,296
  • 1
  • 22
  • 42
  • I think OP already has the module installed `src/app/home/home.component.ts(2,10): error TS2305: Module '"../../../node_modules/rxjs/Observable"' has no exported member 'Observable'`. Its saying that there is no member in `rxjs/Observable`. For this to occur the dependency should already have been installed. – Plochie Dec 25 '19 at 09:38
  • Also installing `rxjs-compat` is just a workaround for removing the error, you already have `Observable` in `rxjs`, so i dont think there is any need to install `rxjs-compat` dependency. Please share your views if this does not make any sense. – Plochie Dec 25 '19 at 09:43
  • If OP already the has module why is it saying `Cannot find module 'rxjs-compat/Observable'.` ? – Selaka Nanayakkara Dec 25 '19 at 10:07
  • Also according to this link [here](https://stackoverflow.com/questions/52388927/cannot-find-module-rxjs-compat-observable) your suggestion is the workaround. – Selaka Nanayakkara Dec 25 '19 at 10:13
  • I think you misread, please read answer from Jandro. Also read the documentation https://github.com/ReactiveX/rxjs/blob/master/docs_app/content/guide/v6/migration.md#dropping-the-compatibility-layer – Plochie Dec 25 '19 at 10:25
0

You can try this:

npm i rxjs

import { Observable } from 'rxjs'
סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68