RXJS: TypeError: this._subscribe is not a function

I port the ionic 3.8 application to 3.9.2. This migration includes an update for RXJS 5.5

Now I am experiencing this error:

TypeError: this._subscribe is not a function. (In 'this._subscribe(sink)', 'this._subscribe' is an instance of t)

After several hours of debugging, I found out that this part of the code is related to an error:

 protected observeConnectionState() { // rxjs/observable/of of(new Event('disconnect')) .pipe( // rxjs/operators/merge merge(connect$), merge(disconnect$), // Map eventname to string (rxjs/operators/map) map((e: IEvent) => { return e.eventName == 'connect' ? 'connected' : 'disconnected'; }) ) // Apply to class context .subscribe((newConnectionState) => { // this.connectionState$ is a BehaviorSubject this.connectionState$.next(newConnectionState); }); } 

ADDITIONAL INFORMATION

+7
source share
2 answers

Ok, I found a problem. And this is not connected with Cordoba.

For other people facing this problem: Forget stack tracing - this is useless. In my case, in the this.connectionState$ subscriber, I tried to create an Observable from a promise. But I did it wrong.

Here is what was wrong:

 import { Observable } from 'rxjs/Observable'; //... const myObservable$ = Observable.create(myPromise); 

Here's how it should be done:

 import { fromPromise } from 'rxjs/observable/fromPromise'; // ... const myObservable$ = fromPromise(myPromise); 
+4
source

I received exactly the same error message in one of my corner applications when performing an update when I replaced Observable.of(someval as any) with new Observable(someval as any) .

Error: unclean (in promise): TypeError: this._subscribe is not a function

I also tried to make it Observable.create(someval as any) but with the same error.

Decision

Replacing it with of(someval as any) solved the problem for me.

 import { of } from 'rxjs'; // use it just like this of(retval as any); 

verbose error message

ERROR error: impurity (in promise): TypeError: this._subscribe is not a function TypeError: this._subscribe is not a function in Observable.push ../ node_modules / rxjs / _esm5 / internal / Observable.js.Observable._trySubscribe (Observable. js: 42) in Observable.push ../ node_modules / rxjs / _esm5 / internal / Observable.js.Observable.subscribe (Observable.js: 28) in MapOperator.push ../ node_modules / rxjs / _esm5 / internal / operators / map.js.MapOperator.call (map.js: 18) in Observable.push ../ node_modules / rxjs / _esm5 / internal / Observable.js.Observable.subscribe (Observable.js: 23) in MapOperator.push ../ node_modules / rxjs / _esm5 / internal / operators / map.js.MapOperator.call

+1
source

Source: https://habr.com/ru/post/1273278/


All Articles