question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Type helpers loose class-validator/class-transformer metadata in Yarn PnP environments

See original GitHub issue

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

@nestjs/swagger uses @nestjs/mapped-types which uses class-validator and class-transformer (if they’re present) to inherit validation/transformer metadata.

  1. @nestjs/swagger brings @nestjs/mapped-types as dependency.
  2. @nestjs/mapped-types requires class-validator and class-transformer as optional peer dependencies.
  3. @nestjs/swagger doesn’t provide class-validator and class-transformer.
  4. @nestjs/swagger -> @nestjs/mapped-types checks whether class-validator and class-transformer are present, sees that they aren’t and doesn’t inherit metadata (ref).

Yarn PnP doesn’t allow implicit requirements which may cause undefined behaviour. It means Yarn PnP expects from @nestjs/swagger to satisfy @nestjs/mapped-types peer/optional dependencies since it’s the direct dependency.

Minimum reproduction code

https://gist.github.com/khmm12/c2a4bdab7dfa82d33f06c45a768ad6d7

Steps to reproduce

No response

Expected behavior

I see 2 possible solutions:

  • @nestjs/swagger should specify @nestjs/mapped-types as peer dependency instead of dependency.
  • @nestjs/swagger should specify class-validator and class-transformer as optional dependencies.

Package version

6.13

NestJS version

No response

Node.js version

No response

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Reactions:1
  • Comments:12 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
kamilmysliwieccommented, Nov 10, 2022

Thanks for chiming in & clarifying @arcanis, and for a thorough discussion @khmm12. Appreciate your time!

Since it doesn’t hurt to explicitly add the inner package’s peer dependencies, let’s just add them in to be compatible with Yarn PnP. Would you like to create a PR @khmm12? Let me know if you’re busy and if so I’ll take care of this myself!

1reaction
khmm12commented, Nov 10, 2022

@kamilmysliwiec I’ll create PRs for @nestjs/swagger and @nestjs/graphql 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Inherit peer dependency ranges from your own ... - GitHub
Type helpers loose class-validator/class-transformer metadata in Yarn PnP environments nestjs/swagger#2169.
Read more >
Plug'n'Play | Yarn - Package Manager
To address this problem, Yarn ships with a "loose" mode which will cause the PnP linker to work in tandem with the node-modules...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found