ReactiveX / rxjs

A reactive programming library for JavaScript
https://rxjs.dev
Apache License 2.0
30.64k stars 3k forks source link

TypeError: Observable.of is not a function since rxjs 6.3.0 #4070

Closed FrancescoBorzi closed 5 years ago

FrancescoBorzi commented 6 years ago

After updating rxjs from version 6.2.x to version 6.3.0, the following:

import 'rxjs/add/observable/of';
// or 
import { Observable } from 'rxjs/Observable';

Observable.of(...)

Are not working anymore. The only way to make it work now is by using:

import { of } from 'rxjs/observable/of';

of(...)

is this a bug or the intended behaviour? It looks a breaking change to me :(

s25g5d4 commented 5 years ago

Please find sample code here: https://github.com/s25g5d4/rxjs-path-mapping-issue

Ristaaf commented 5 years ago

@s25g5d4 Great information, thanks!

As for the first solution/workaround it actually means migrating halfway to rxjs 6, this problem is mainly about code that needs to work both with rxjs 5 and 6, typically in existing libraries you use, Kendo as an example has clearly stated that as long as they support rxjs 5 (which will be at least for another year), they will use the rxjs 5 syntax and require you to use rxjs-compat if using rxjs 6.

The workaround for Angular CLI is great (even if of course we would like to avoid workarounds as much as possible), did not know it was possible to solve that way thanks for the information and education on the matter!

rajkumarm-iprogrammer commented 5 years ago

Force or reinstall exact version of rxjs@6.2.2 and rxjs-compat@6.2.2.

This one is worked for me as well. Thanks :+1: :

KevinKelchen commented 5 years ago

I updated to Ionic 4 Beta 17 (Angular 7) which resulted in going from RxJS 6.2.2 to 6.3.3. Editing the tsconfig.app.json file with the paths workaround was to no avail for me.

Instead, I am sticking with RxJS 6.3.3 but am leaving rxjs-compat at 6.2.2. Due to this issue, I will probably need to just bite the bullet and do the full upgrade to RxJS 6 before we release our app.

ashraf-cslsoft commented 5 years ago

Instead of import 'rxjs/add/observable/of';

Below works for me import { of } from 'rxjs';

monelseZA commented 5 years ago

Import : import { of as observableOf} from 'rxjs';

and Change Observable.of to observableOf