-
Notifications
You must be signed in to change notification settings - Fork 812
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
question: decorator information missing from shared project #181
Comments
Looks like related to #132. |
@zelid Do you import your |
Hey @zelid! I just gave a look and it works for me. There are 3 things you miss probably. No metadata is emittedYou need to build your shared project, and you need to build it with the right settings. (Technically you don't need to, but you should.) Your
(Technically Shared classes must be importedYou must import your shared classes at least once at the beginning of your project. Otherwise, the decorator metadata is not recorded. You can do it easily by re-exporting everything in the root of your
You must validate an instance of the class.
I have created an example, my folder structure is:
Where my import { validateSync } from 'class-validator';
import { CreateLoginInput } from 'shared-lib';
const instance = new CreateLoginInput();
console.log(validateSync(instance)); And import { Length, IsEmail } from 'class-validator';
export class CreateLoginInput {
@Length(2, 20)
public name!: string
@IsEmail()
public email!: string
} I attach the complete example as an attachment: class-validator-181.zip Please let me know if this solved your issue. |
@NoNameProvided thanks for detailed explanation!
@NoNameProvided how do you manage your shared library code, do you put it as separate private/local The issue with my code was indeed with the The second approach I've tired is including Local private |
We use private npm packages. I will go ahead and close this as solved, let me know if you have any other quetstion. |
Just a heads up to anyone who encounters something like this, definitely look into #132 which was causing our issues. Specifically this comment #132 (comment) which explains the issue quite clearly. |
I have a need to use the same decorated input class like:
class-validator
works fine when decorated class and validation action are in the same project.When used in a shared project config like:
client-app
,server-app
,shared-lib
whereCreateLoginInput
is placed in a shared lib and validation is done in both client and server app it stops to work and validation always returns no errors.server-app
andclient-app
are separate projects with very different set of node_modules and can't be placed inside one project. I movedCreateLoginInput
class toshared-lib
project to make other projects consume input validation.When
CreateLoginInput
is included fromshared-lib
validation stops to work, probably the decorator metadata is missed.How to configure
class-validator
to make validation work when classes are included from a shared project?The text was updated successfully, but these errors were encountered: