Cannot find module rxjs/Observable/fromPromise

Hi All,
Strange issue here, I am importing the fromPromise module as follows;

import { fromPromise } from 'rxjs/Observable/fromPromise';

It runs fine on my Mac. However cloning, building and running ionic serve on Windows or Linux gives me the following error in the console and on the browser.

Uncaught Error: Cannot find module "rxjs/Observable/fromPromise"
Ionic Framework: 2.2.0
Ionic Native: 2.4.1
Ionic App Scripts: 1.1.4
Angular Core: 2.4.8
Angular Compiler CLI: 2.4.8
Node: 6.10.0
OS Platform: Linux 3.16
Navigator Platform: Linux x86_64
User Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1

Any help with this would be greatly appreciated.

I’ve used this successfully, though I don’t know whether it will make a difference for you.

import 'rxjs/add/observable/fromPromise';

Edit: also it occurs to me, are you importing repeatedly? You only need to do it once for your entire application, unlike the injection you might be used to.

I do only use it the once, although would you suggest that be placed within the app.component.ts file? Another thing is if I use your suggestion, how would I call fromPromise()? I currently have the following;

  .subscribe(data => {
    this.something = data;
  }, error => console.error(error), () => {
    console.log('Observable complete.');
import { Observable } from 'rxjs/Observable';
import { Subscription } from 'rxjs/Subscription';
import 'rxjs/add/observable/fromPromise';

subscription: Subscription;
this.subscription = Observable.fromPromise(your promise here).subscribe(val => console.log(val));

I’ve seen placement in app.component.ts recommended online. I haven’t tried enough things to be able to say whether that’s best practice. What if I only use skip in one place and then delete it? Will the linter always catch that I don’t need the import anymore? I’m just not sure. So I don’t have good advice there, sorry.

That’s brilliant, thanks for the support :slight_smile:

There are a lot of subtle syntax differences between RxJS 4 and 5, and it isn’t always clear which you are looking at when you stumble across things on the web.

Reactive-Extensions/RxJS = RxJS 4. Bad. Avoid.
ReactiveX/RxJS = RxJS 5. Good. Believe.

@rapropos Thanks for the heads up. Would be great if that was included in the Ionic docs.