#@nestjs/mapped-type lose class-transformer decorator since 0.3.2 on client side

22 messages · Page 1 of 1 (latest)

verbal bronze
#

I have a project in a monorepo that share type between front and back. In this type, we use mapped type (OmitType, PartialType...).

When we use class transformer server side to transform inputs, it works fine. But if we do the same thing on client client, it doesn't work.

Codesandbox :
https://codesandbox.io/s/class-validator-forked-vdrkl5?file=/src/index.ts

It works perfectly in 0.3.1, but not since 0.3.2

#

@nestjs/mapped-type lose class-transformer decorator since 0.3.2 on client side

verbal bronze
#

Someone has any idea ? 😟

verbal bronze
#

no one is facing the same issue ?

icy kraken
#

What do you use to build/run your code on the client side?

#

I'm not super familiar with using class-transformer on the browser side, but if I have the steps to take I can at least take a look

verbal bronze
#

The CodeSandbox link I sent allows you to reproduce the problem.
I tested building my project in different ways but the problem remains the same.
If there is any information missing or if I can help, please let me know!

icy kraken
#

Right, I saw that code sandbox reproduced it, but I wanted to know how to do that locally too, so I can modify packages a bit more directly for testing purposes

verbal bronze
icy kraken
#

This'll work, yeah.

#

The first thing I'm noticing is that theprototype of a.props isn';t function B, but is instead Object. Gonna try to see if I can figure out why cause that's interesting

#

And as you've said, in a Node environment, this works as expected

icy kraken
#

Okay, I think the issue is that /mapped-types is reading the metadata storage object from class-transformer/cjs/storage whereas when the parcel bundler is importing class-transformer it's importing the esm5 version of the package class-transformer/esm5 so the MetadataStorage object, when Nest is trying to read it in the browser setting, is empty, there's no metadata in the map.

IF class-transformer were to use the Reflect API and store it directly on the object, this could be avoided pretty easily, but as that's not the case, we'd have to figure out some way to determine if class-transformer should be imported via a require statement or the esm import.

The other possible solution would be to have all of Nest's code use ESM, which is an eventual goal to align with the ecosystem, but it's not a huge rush at the moment as tooling still isn't just great around it, and it would be a rather large breaking change to existing code bases

verbal bronze
#

Thanks for the investigation!
What made this work with class-transformer 0.3.1 ?

icy kraken
#

Oh boy, that's a great question

verbal bronze
icy kraken
#

Ah, that has to do with the main/mdoule/etc fields in the package.json

verbal bronze
#

Hmmm okay.
What can i do for my project ? Stay in 0.3.1 or something else ?
What can i do for helping to fix this issue on class-transformer or nestjs ?

icy kraken
#

Right now, just stay on 0.3.1

verbal bronze
#

Is there anything new regarding this issue ?
I would like to upgrade to the latest version of nest and I'm afraid it will block me

tropic rivet
verbal bronze
#

Yes...