class-validator icon indicating copy to clipboard operation
class-validator copied to clipboard

fix: package does not work in a mono repo

Open trixobird opened this issue 11 months ago • 1 comments

Description

class-validator fails with TypeError: Cannot read properties of undefined (reading 'constructor') in a mono repo

Minimal code-snippet showcasing the problem I have created a repository for you: https://github.com/trixobird/class-validator-bug. If you do pnpm --filter=@repo/dto dev it works. If you do pnpm --filter=caller dev it does not.

Expected behavior

The pnpm --filter=caller dev should not produce any errror

Actual behavior

This error is being thrown:

~/w/[...]/class-validator-bug/packages/dto git:[main]
pnpm --filter=caller dev

> [email protected] dev /[...]/class-validator-bug/apps/caller
> tsx src/index.ts

/[...]/class-validator-bug/node_modules/.pnpm/[email protected]/node_modules/src/decorator/common/ValidateBy.ts:27
      target: object.constructor,
                     ^


TypeError: Cannot read properties of undefined (reading 'constructor')
    at <anonymous> (/[...]/class-validator-bug/node_modules/.pnpm/[email protected]/node_modules/src/decorator/common/ValidateBy.ts:27:22)
    at __decorateElement (/[...]class-validator-bug/packages/dto/src/index.ts:2:2736)
    at <anonymous> (/[...]/class-validator-bug/packages/dto/src/index.ts:16:3)
    at Object.<anonymous> (/[...]/class-validator-bug/packages/dto/src/index.ts:54:2)
    at Module._compile (node:internal/modules/cjs/loader:1565:14)
    at Object.transformer (/[...]/class-validator-bug/node_modules/.pnpm/[email protected]/node_modules/tsx/dist/register-DCnOAxY2.cjs:2:1186)
    at Module.load (node:internal/modules/cjs/loader:1318:32)
    at Function._load (node:internal/modules/cjs/loader:1128:12)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:219:24)

Node.js v22.12.0
/[...]/class-validator-bug/apps/caller:
 ERR_PNPM_RECURSIVE_RUN_FIRST_FAIL  [email protected] dev: `tsx src/index.ts`
Exit status 1

trixobird avatar Feb 10 '25 15:02 trixobird

Running into this as well. Did you ever come up with a solution?

I believe it's an issue with tsconfig not transforming the file, but no matter what I values I have in the tsconfig "include" I can't get it working from the package directory.

However if I run from the workspace root then it works,

sarendipitee avatar Mar 27 '25 16:03 sarendipitee