Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'rxjs' and 'reflect-metadata' as peer dependencies #83

Closed
euanhunteratom opened this issue Aug 21, 2023 · 2 comments
Closed

Add 'rxjs' and 'reflect-metadata' as peer dependencies #83

euanhunteratom opened this issue Aug 21, 2023 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@euanhunteratom
Copy link

euanhunteratom commented Aug 21, 2023

Overview
Add rxjs and reflect-metadata to peerDependencies of (I think) packages/core/package.json.

Versions

nestjs-cls: 3.5.0
NodeJS: v16.16.0
Yarn: 3.3.1 (using Yarn PnP mode)
typescript: 4.9.4

Details
When trying to import nestjs-cls, I get the following error

Cannot find module 'rxjs' from 'REDACTED/.yarn/__virtual__/nestjs-cls-virtual-c54616727a/0/cache/nestjs-cls-file-29ea52353d-10faf375e2.zip/node_modules/nestjs-cls/dist/src/lib/cls-initializers'

We use Yarn in PnP (Plug'n'Play) mode. I believe this is a bit more strict with module resolution, particularly around transitive dependencies. Since lib/cls-initializers/cls.interceptor.ts uses rxjs directly but this isn't declared as an explicit dependency of nestjs-cls (except in "dev" mode) I think Yarn is blocking this being imported. Same applies for reflect-metadata in lib/cls-initializers/use-cls.decorator.ts.

Fix
For 3.5.0, I think the fix would be adding rxjs and reflect-metadata to the root package.json in peerDependencies would fix this (not sure what version constraints). With the yarn workspace refactor, I think the same fix should instead be applied to packages/core/package.json

Workaround
I was able to workaround this by downloading the v3.5.0 source code, making the above change to peerDependencies, and including this as a file: dependency in our package.json files. This works but isn't really practical to integrate into our build system, so this issue probably blocks us using this package. See reply below for much better workaround using packageExtensions

N.B. thanks for the awesome package using AsyncLocalStorage, looking forward to being able to use it.

@Papooch Papooch added the bug Something isn't working label Aug 22, 2023
@Papooch
Copy link
Owner

Papooch commented Aug 22, 2023

Yeah, that is a mistake, thank you for spotting this! The migration to yarn is not complete yet (the latest published version 3.5.0 is still based on the npm based structure), so that's why I haven't bumped into this earlier.

You can fix it in your repository right now (without altering nestjs-cls's source) by updating your .yarnrc.yml with this:

packageExtensions:
  "nestjs-cls@*":
    peerDependencies:
      "reflect-metadata": "*"
      "rxjs": "*"

(reference: https://yarnpkg.com/configuration/yarnrc/#packageExtensions)

I will definitely address this in the new version though!

@Papooch Papooch self-assigned this Aug 22, 2023
@Papooch
Copy link
Owner

Papooch commented Aug 29, 2023

Fixed in v3.5.1

@Papooch Papooch closed this as completed Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants