Nest: Move rxjs to peerDependencies to allow custom versions usage

Created on 10 May 2017  ยท  22Comments  ยท  Source: nestjs/nest

Error for client example from https://kamilmysliwiec.gitbooks.io/nest/content/real-time/microservices/basics.html

        this.client.send(pattern, data)
            .catch((err) => Observable.empty())

```
[ts] Property 'catch' does not exist on type 'Observable<{}>'.

this does not help
```ts
import { Observable } from 'rxjs';
import 'rxjs/add/operator/catch';

skipping via

(<any> this.client).send(pattern, data)

provides error at runtime

[Nest] 9905   - 5/10/2017, 3:44:13 AM   [ExceptionsHandler] this.client.send(...).catch is not a function
TypeError: this.client.send(...).catch is not a function

Most helpful comment

Hi @artaommahe,
Since ~2.0.0 rxjs is used as a peerDependency.

All 22 comments

Hi @artaommahe !

This worked for me:

import { Observable } from 'rxjs/Observable';
import "rxjs/add/operator/catch";
import "rxjs/add/observable/empty";

I'm importing Observable from its file instead of index file "rxjs". You need to import the Observable empty as well. I hope it helps! ๐Ÿ˜„

@beagleknight yep, i tried this cases and have an error..
image

I think you are missing a return statement in the catch callback:

this.client.send(pattern, data)
  .catch((err: any) => { console.log('error', err); return Observable.empty(); })
  .subscribe(...)

I have this code working:

 const dogs = await this.client.send({ cmd: "woof" }, [])
                  .catch((err) => Observable.of(err))
                  .toPromise();

I uploaded the code to a public repository so you can check it ๐Ÿ˜„
https://github.com/beagleknight/nest-test/blob/master/lib/users/users.controller.ts

Yeah, missing return in catch, also, FYI .empty() only fires onComplete, and your subscribe doesn't supply an onComplete, so the res wouldnt be sent even if you added a return. Observable.of() is likely what you want to be returning.

I think you are missing a return statement in the catch callback:

i miised, but error marks

[ts] Property 'catch' does not exist on type 'Observable<{}>'.

I found a reason - having "rxjs": "^5.4.0", in my package.json provides this error.
Looks like we forced to use nestsrxjs version without ability to update to last one..

IMHO this should be fixed via moving rxjs nest dependency to peerDependencies block like angular team did. Same to other used libs like express, socket.io.

@artaommahe Peer deps is deprecated with npm3 if I recall. You're able to use whatever version of rxjs you wish without issue regardless of what version Nest uses, assuming you have npm3 installed (I'm currently doing this now).

Given the above error, I'd assume you need to be sure you include the full Rx library if you want to use catch, or use the operator add import to import it. Have a look at the import section under Installation and Usage here:
https://github.com/ReactiveX/rxjs

import Rx from 'rxjs/Rx';
Rx.Observable.of(1,2,3)

or

import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/map';
Observable.of(1,2,3).map(x => x + '!!!'); // etc

edit: just reread the OP, I see you tried the import. Taking another look

As far as the dependencies - grep '[email protected]' in my npm list output and you'll see I'm running 5.4.0 alongside nest:

$ npm list
projectnamehere
โ”œโ”€โ”€ @types/[email protected]
โ”œโ”€โ”€ @types/[email protected]
โ”œโ”€โ”ฌ @types/[email protected]
โ”‚ โ””โ”€โ”ฌ @types/[email protected]
โ”‚   โ”œโ”€โ”€ @types/[email protected]
โ”‚   โ””โ”€โ”ฌ @types/[email protected]
โ”‚     โ””โ”€โ”€ @types/[email protected]
โ”œโ”€โ”ฌ @types/[email protected]
โ”‚ โ””โ”€โ”€ @types/[email protected]
โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚ โ””โ”€โ”€ [email protected]
โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚ โ””โ”€โ”ฌ [email protected]
โ”‚   โ”œโ”€โ”€ [email protected]
โ”‚   โ””โ”€โ”ฌ [email protected]
โ”‚     โ””โ”€โ”€ [email protected]
โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ””โ”€โ”€ [email protected]
โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚ โ””โ”€โ”€ [email protected]
โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”‚ โ””โ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”‚   โ””โ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚ โ”‚ โ””โ”€โ”ฌ [email protected]
โ”‚ โ”‚   โ””โ”€โ”€ [email protected]
โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”‚ โ””โ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”‚   โ””โ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”‚ โ””โ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”‚   โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”‚   โ”‚ โ””โ”€โ”€ [email protected]
โ”‚ โ”‚ โ”‚   โ””โ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”‚     โ””โ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ””โ”€โ”ฌ [email protected]
โ”‚   โ”œโ”€โ”€ [email protected]
โ”‚   โ”œโ”€โ”ฌ [email protected]
โ”‚   โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚   โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚   โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚   โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚   โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚   โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚   โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚   โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚   โ”‚ โ””โ”€โ”ฌ [email protected]
โ”‚   โ”‚   โ”œโ”€โ”€ [email protected]
โ”‚   โ”‚   โ””โ”€โ”€ [email protected]
โ”‚   โ”œโ”€โ”€ [email protected]
โ”‚   โ”œโ”€โ”€ [email protected]
โ”‚   โ”œโ”€โ”ฌ [email protected]
โ”‚   โ”‚ โ””โ”€โ”€ [email protected]
โ”‚   โ”œโ”€โ”ฌ [email protected]
โ”‚   โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚   โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚   โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚   โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚   โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚   โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚   โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚   โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚   โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚   โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚   โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚   โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚   โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚   โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚   โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚   โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚   โ”‚ โ”‚ โ””โ”€โ”ฌ [email protected]
โ”‚   โ”‚ โ”‚   โ””โ”€โ”€ [email protected]
โ”‚   โ”‚ โ””โ”€โ”€ [email protected]
โ”‚   โ””โ”€โ”ฌ [email protected]
โ”‚     โ”œโ”€โ”€ [email protected]
โ”‚     โ”œโ”€โ”ฌ [email protected]
โ”‚     โ”‚ โ””โ”€โ”€ [email protected]
โ”‚     โ””โ”€โ”€ [email protected]
โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ””โ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”ฌ [email protected]
โ”‚ โ””โ”€โ”€ [email protected]
โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚ โ””โ”€โ”ฌ [email protected]
โ”‚   โ””โ”€โ”€ [email protected]
โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”‚ โ””โ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”‚   โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ”‚   โ””โ”€โ”€ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚ โ””โ”€โ”ฌ [email protected]
โ”‚   โ”œโ”€โ”€ [email protected]
โ”‚   โ”œโ”€โ”ฌ [email protected]
โ”‚   โ”‚ โ””โ”€โ”€ [email protected]
โ”‚   โ”œโ”€โ”€ [email protected]
โ”‚   โ”œโ”€โ”€ [email protected]
โ”‚   โ”œโ”€โ”ฌ [email protected]
โ”‚   โ”‚ โ””โ”€โ”ฌ [email protected]
โ”‚   โ”‚   โ””โ”€โ”€ [email protected]
โ”‚   โ”œโ”€โ”ฌ [email protected]
โ”‚   โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚   โ”‚ โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚   โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚   โ”‚ โ””โ”€โ”ฌ [email protected]
โ”‚   โ”‚   โ”œโ”€โ”ฌ [email protected]
โ”‚   โ”‚   โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚   โ”‚   โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚   โ”‚   โ”‚ โ”‚ โ””โ”€โ”ฌ [email protected]
โ”‚   โ”‚   โ”‚ โ”‚   โ””โ”€โ”€ [email protected]
โ”‚   โ”‚   โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚   โ”‚   โ”‚ โ””โ”€โ”ฌ [email protected]
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ [email protected]
โ”‚   โ”‚   โ”œโ”€โ”ฌ [email protected]
โ”‚   โ”‚   โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚   โ”‚   โ”‚ โ”œโ”€โ”ฌ [email protected]
โ”‚   โ”‚   โ”‚ โ”‚ โ””โ”€โ”€ [email protected]
โ”‚   โ”‚   โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚   โ”‚   โ”‚ โ””โ”€โ”ฌ [email protected]
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”ฌ [email protected]
โ”‚   โ”‚   โ”‚   โ”‚ โ””โ”€โ”€ [email protected]
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ [email protected]
โ”‚   โ”‚   โ””โ”€โ”€ [email protected]
โ”‚   โ”œโ”€โ”€ [email protected]
โ”‚   โ”œโ”€โ”€ [email protected]
โ”‚   โ”œโ”€โ”€ [email protected]
โ”‚   โ”œโ”€โ”ฌ [email protected]
โ”‚   โ”‚ โ”œโ”€โ”€ [email protected]
โ”‚   โ”‚ โ””โ”€โ”ฌ [email protected]
โ”‚   โ”‚   โ””โ”€โ”€ [email protected]
โ”‚   โ”œโ”€โ”€ [email protected]
โ”‚   โ”œโ”€โ”€ [email protected]
โ”‚   โ””โ”€โ”€ [email protected]
โ””โ”€โ”€ [email protected]

As far as the dependencies - grep '[email protected]' in my npm list output and you'll see I'm running 5.4.0 alongside nest:

ofc it will be here due to nest dependency. I'm talking about explicitly added rxjs in your own package.json.
Just clone example repo above (https://github.com/beagleknight/nest-test), add

    "rxjs": "^5.4.0"

to package.json "dependencies" list, run


open ./lib/users/users.controller.ts and see same error
image
```
[ts] Property 'catch' does not exist on type 'Observable<{}>'.
````

perhaps you're misreading that list output. If you'd run the search, youd see 5.4.0 is brought in directly under my project, due to being in package.json, and 5.0.3 is brought in by Nest.

Note that 5.4.0 is a primary dependency and 5.0.3 is a 2nd or "peer" but npm3 nests it under Nest

โ”œโ”€โ”ฌ [email protected]
...
โ”‚ โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”ฌ [email protected]
โ”‚ โ””โ”€โ”€ [email protected]

Here's my dependencies block:

"dependencies": {
    "bcrypt-as-promised": "^1.1.0",
    "body-parser": "^1.17.1",
    "jsonwebtoken": "^7.4.0",
    "mysql": "^2.13.0",
    "nest.js": "1.0.6",
    "passport": "^0.3.2",
    "passport-jwt": "^2.2.1",
    "reflect-metadata": "0.1.10",
    "rxjs": "^5.4.0",
    "typeorm": "0.0.11",
    "typescript": "^2.2.1"
  },

and here's a snippet of my use of catch

        this.connectionSubject
            .map(n => `Connected to ${databaseConfigInfo}`)
            .catch(e => Rx.Observable.of(`Failed to connect to ${databaseConfigInfo}. Here's why: ${e}`))
            .subscribe(console.log);

@zachgrayio yep, missed it. But there is still an error for example repo above with added to tsconfig rxjs lib.

I don't use yarn much, but off top of my head, I'm wondering if you have a cached version of rxjs in yarn and it's still using it instead of 5.4.0 dependency you added to your package.json.

under npm, when changing versions im always sure to rm -rf ./node_modules && npm i to ensure the version of libs i think im using are always in use.

have you run a yarn cache clean and yarn install after updating package.json?

@zachgrayio you can simply repeat it with npm (just made it)

git clone https://github.com/beagleknight/nest-test
cd nest-test

add rxjs to package.json dependencies list

  "dependencies": {
    "body-parser": "^1.17.1",
    "express": "^4.15.2",
    "nest.js": "^1.0.2",
    "rxjs": "^5.4.0"
  },
npm cache clean
npm i

open ./lib/users/users.controller.ts and see error on catch

alright, ill take a look

Looks like an rxjs5 modularity issue.

Making this change in client-prox.d.ts solves the issue it seems:

import * as Rx from 'rxjs/Rx'; // import all of rx. using the operator add import HERE solves the issue too
import { Observer } from 'rxjs/Observer';

export declare abstract class ClientProxy {
    abstract sendSingleMessage(pattern: any, callback: any): any;
    send<T>(pattern: any, data: any): Rx.Observable<T>;
    createObserver<T>(observer: Observer<T>): (err: any, result: any) => void;
}

Might be best to open an issue over on rxjs to see what the preferred solution here is, I'm not entirely sure - though seems like its probably a pretty common issue.

In the meantime though, this works either way because subscribe is always present on Observable.

    this.client.send<string>({ cmd: "woof" }, [])
      .subscribe(
          dogs => {
            res.status(HttpStatus.OK).json(dogs);
          }, e => {
            console.log(e);
          })

also its worth noting that you were returning an Observable<Error> from your catch, which you were turning into a promise, then resolving and returning in your call to json() which would try to send it down in the response... where as the success case would have been some other type, maybe a domain model or something you'd want to serialize and return to the user. Observable.catch() is meant to catch errors and recover without breaking the chain, maybe return an empty array or something, usually not the error itself.

edited to add: perhaps some attention should be given to method send<T>(pattern: any, data: any): Observable<T>; to avoid implementations like the above that don't include strong typings and thus don't benefit from typescript compile errors when types are botched. Also, am I correct in assuming that T really should be the type of whatever the ack is going to be, not the type of what we're sending? (in the case above, it picked up the type as Observable<{}> I think.

@zachgrayio yep, i understand that it's too synthetic case with catch but looks like there will be issues with any operator (that is not imported in nest lib) and 2 rxjs versions (from nest and current app).

@zachgrayio also i dont find anything about peerDependencies deprecation for last year. Official npm docs have only this

NOTE: npm versions 1 and 2 will automatically install peerDependencies
if they are not explicitly depended upon higher in the dependency tree.
In the next major version of npm (npm@3), this will no longer be the case.
You will receive a warning that the peerDependency is not installed instead.

and old blog posts about deprecation without smth official

To be clear, this isn't a problem with bringing in other versions of Rx alongside Nest. I've done this just fine a few times.

The issue is really that use of import 'rxjs/add/operator/catch'; and so on fails to effect the Observable returned by the send() method of the ClientProxy abstract class.

The issue is really that use of import 'rxjs/add/operator/catch'; and so on fails to effect the Observable returned by the send() method of the ClientProxy abstract class.

Cause there is 2 different rxjs versions running at the same time - from nest dependencies and from your app. Importing operator in app code affects only app rxjs version instance.
Same thing with any other main lib used by nest - adding newer version of express as dependency of your app will not affect version that will be used by used.
This is the reason why peerDependencies using is important and why angular team did so for rxjs and zone.js libs - upgrading to newest verison by app developer could be very important when there is critical fixes or important new features.

Hi @artaommahe,
Since ~2.0.0 rxjs is used as a peerDependency.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

janckerchen picture janckerchen  ยท  3Comments

thohoh picture thohoh  ยท  3Comments

tronginc picture tronginc  ยท  3Comments

2233322 picture 2233322  ยท  3Comments

rafal-rudnicki picture rafal-rudnicki  ยท  3Comments