Comments (22)
Hi @artaommahe,
Since ~2.0.0
rxjs is used as a peerDependency
.
from nest.
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.
from nest.
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! 😄
from nest.
@beagleknight yep, i tried this cases and have an error..
from nest.
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();
from nest.
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
from nest.
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.
from nest.
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
.
from nest.
@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
from nest.
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]
from nest.
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
yarn
open ./lib/users/users.controller.ts
and see same error
[ts] Property 'catch' does not exist on type 'Observable<{}>'.
from nest.
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);
from nest.
@zachgrayio yep, missed it. But there is still an error for example repo above with added to tsconfig rxjs lib.
from nest.
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?
from nest.
@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
from nest.
alright, ill take a look
from nest.
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.
from nest.
@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).
from nest.
@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
from nest.
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.
from nest.
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.
from nest.
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.
from nest.
Related Issues (20)
- cannot run debugger with custom webpack config HOT 1
- Extended ConsoleLogger prints undefined on every log message HOT 2
- Argument of type 'FastifyCookie' is not assignable to parameter of type 'FastifyPluginCallback<FastifyCookieOptions> | FastifyPluginAsync<FastifyCookieOptions> | Promise<...> | Promise<...>'. HOT 2
- Kafka microservice throw Error when first connect to server HOT 1
- Decouple Nest's DI container from Node API HOT 5
- KafkaJs seems not maintained anymore HOT 2
- Add `@RawBody()` decorator to avoid having to always resort to `@Req()` with specific types and parameters HOT 1
- Nest can't resolve dependencies of the custom Validator with Repository HOT 2
- issue opened on wrong repo HOT 1
- Bad typings for Fastify server `enableCors` method, `delegator` property is missing HOT 3
- When I use Nestjs in my own build monorepo project, there seems to be some bugs with "@nestjs/core postinstall". HOT 1
- Improve experience when initialisation error occurs HOT 1
- When I introduce a configuration file from outside the project, an error occurs: Cannot find module HOT 3
- circular dependecy error due to reflect-metadata dependency HOT 1
- Validation Pipe is not executed HOT 2
- Error cause is not logged in dev:watch mode
- Use multiple env files HOT 1
- Calling grpcClient.start in server-grpc is no longer necessary since version 1.10.x HOT 2
- Error: Unknown authentication strategy "jwt" for Project with multi apps projects HOT 11
- broken path in build output HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nest.