#DTOs with class transformer annotations exported to own lib are ignored

24 messages · Page 1 of 1 (latest)

sage rampart
#

Hi,

I created a npm library for all my DTOs, because I need them in multiple microservices. This works fine for validation, but if I have to use transformation with the annotations @Transform() or @Type() they will be ignored.

Any ideas why this could happen. I you only have some buzzwords for me, this would be cool, too. Don't know what to search for in google 😅

#

Btw: When I define such a DTO with a transform annotation in the service directly it works like a charm.

meager sequoia
#

My guess is that you build the library before publishing, and that during the build some information is lost. There are two important config options that have to be enabled during the build - experimental decorators, and decorator metadata.

sage rampart
#

I allready thought in that direction and also exported the unbuild src folder to the lib and tried to include the file in the ts build config

#

I will try your approache

#

it has to be set in the lib or in the service too?

meager sequoia
#

In the lib, then you build and publish a new version, and pull that update in the service.

sage rampart
#

i will try it directly 🙂

#

I saw that I already has this flags enabled

#

Do you have any other ideas?

meager sequoia
#

Not really, sorry. I'd try looking for a similar library to compare the configs and package.json stuff.

sage rampart
#

I found this link on github with other people having the same issue

meager sequoia
sage rampart
meager sequoia
#

yarn why class-validator

sage rampart
#

I installed the same versions manually

#

IT WORKS !!!!!!

#

@meager sequoia thank you very much

snow pasture
#

You may want to make the library use peerDependencies for c-v/c-t, so that they automatically use the same version as the application that's using the library

sage rampart
#

maybe this could be added to the microservice docs

#

i think it's a commen usecase to have a dto in at least two service, thats communicate with each other