MichalLytek / type-graphql

Create GraphQL schema and resolvers with TypeScript, using classes and decorators!
https://typegraphql.com
MIT License
7.99k stars 674 forks source link

Cannot find module 'class-validator' or its corresponding type declarations #1548

Closed PS1TD closed 9 months ago

PS1TD commented 9 months ago

Describe the Bug When compiling typescript to javascript using tsc getting an error that there is no class-validator module even though I am not using the validation features that typegraphql offers.

To Reproduce Set "module": "nodenext" in tsconfig and run tsc

Expected Behavior Since class-validator is not a dependency but a peer dependency I should not be getting an error if I am not using validation.

Logs

tsc

node_modules/.pnpm/type-graphql@2.0.0-beta.3_graphql-scalars@1.22.4_graphql@16.8.1/node_modules/type-graphql/build/typings/errors/graphql/ArgumentValidationError.d.ts:1:38 - error TS2307: Cannot find module 'class-validator' or its corresponding type declarations.

1 import { type ValidationError } from "class-validator";
                                       ~~~~~~~~~~~~~~~~~

node_modules/.pnpm/type-graphql@2.0.0-beta.3_graphql-scalars@1.22.4_graphql@16.8.1/node_modules/type-graphql/build/typings/schema/build-context.d.ts:1:39 - error TS2307: Cannot find module 'class-validator' or its corresponding type declarations.

1 import { type ValidatorOptions } from "class-validator";
                                        ~~~~~~~~~~~~~~~~~

Found 2 errors in 2 files.

Errors  Files
     1  node_modules/.pnpm/type-graphql@2.0.0-beta.3_graphql-scalars@1.22.4_graphql@16.8.1/node_modules/type-graphql/build/typings/errors/graphql/ArgumentValidationError.d.ts:1
     1  node_modules/.pnpm/type-graphql@2.0.0-beta.3_graphql-scalars@1.22.4_graphql@16.8.1/node_modules/type-graphql/build/typings/schema/build-context.d.ts:1

Environment (please complete the following information):

Additional Context If I install the class-validator package manually I start getting errors with libphonenumber-js https://github.com/typestack/class-validator/issues/1947

Setting "skipLibCheck": true helps ignore those errors but I am not entirely happy with this solution.

MichalLytek commented 9 months ago

Setting "skipLibCheck": true helps ignore those errors but I am not entirely happy with this solution.

We neither, but that's what we've described in the docs: https://typegraphql.com/docs/validation.html#caveats