1

I install rxjs in my vue project. I am trying to import it like this

import {Observable} from 'rxjs/Observable'

I am getting this error always

ERROR in ./node_modules/rxjs/Observable.js
Module not found: Error: Can't resolve 'rxjs-compat/Observable'

If i use import {Observable} from 'rxjs' it is working fine.

rxjs version is

"rxjs": "^6.3.3"

How can i import only Observable inside rxjs?

Sam
  • 2,275
  • 9
  • 30
  • 53

1 Answers1

1

In version 6, you have to use,

import {Observable} from 'rxjs'

In verison 5, you can directly import from rxjs/Observalble

import {Observable} from 'rxjs/Observalble'
Anurag Awasthi
  • 6,115
  • 2
  • 18
  • 32
  • Tried that still same issue. – Sam Oct 30 '18 at 06:18
  • If i import Observable from rxjs directly instead of rxjs/Observable, it will import every thing from rxjs even though i am using Observable. – Sam Oct 30 '18 at 06:22
  • Tried this one `import Observable from 'rxjs/Observable' ` still not working. – Sam Oct 30 '18 at 06:22
  • @Sam Above syntax will only work with version 5.In version 6 they changed it so you will have to use `import {Observable} from 'rxjs'`. See this [answer](https://stackoverflow.com/questions/42376972/best-way-to-import-observable-from-rxjs) – Anurag Awasthi Oct 30 '18 at 06:36
  • its tough learning this stuff when they dont keep the tutorials up to date. Im looking at something on sitepoint and the rxjs stuff simply wont compile. still uses the http object. oh well, if it was easy.... – greg Feb 04 '19 at 02:24