ValidationPipe still uses class-validator package
See original GitHub issueIs there an existing issue for this?
- I have searched the existing issues
Current behavior
When changing the class-validator package to instead use @nestjs\class-validator, I found that ValidationPipe still requires the class-validator package.
This is also verified by this page:
https://docs.nestjs.com/techniques/validationUsePipes(new ValidationPipe
[Nest] 150 - 11/11/2021, 11:00:13 AM ERROR [PackageLoader] The "class-validator" package is missing. Please, make sure to install this library ($ npm install class-validator) to take advantage of ValidationPipe.
#14 77.71 ● process.exit called with "1"
#14 77.71
#14 77.71 59 |
#14 77.71 60 | @Post()
#14 77.71 > 61 | @UsePipes(new ValidationPipe({ transform: true }))
Minimum reproduction code
none yet
Steps to reproduce
npm ci npm test npm run build
Expected behavior
I was hoping the class-validator package would have been detected after installing @nestjs\class-validator
Package
- I don’t know. Or some 3rd-party package
-
@nestjs/common -
@nestjs/core -
@nestjs/microservices -
@nestjs/platform-express -
@nestjs/platform-fastify -
@nestjs/platform-socket.io -
@nestjs/platform-ws -
@nestjs/testing -
@nestjs/websockets - Other (see below)
Other package
NestJS version
8.2.0
Packages versions
"@azure/service-bus": "^7.0.2",
"@nestjs/azure-database": "^2.1.0",
"@nestjs/class-validator": "^0.13.3",
"@nestjs/common": "^8.2.0",
"@nestjs/config": "^1.1.0",
"@nestjs/core": "^8.2.0",
"@nestjs/platform-express": "^8.2.0",
Node.js version
14.18.1
In which operating systems have you tested?
- macOS
- Windows
- Linux
Other
No response
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:19 (8 by maintainers)
Top Results From Across the Web
Validation | NestJS - A progressive Node.js framework
The ValidationPipe makes use of the powerful class-validator package and its declarative validation decorators. The ValidationPipe provides a convenient ...
Read more >class-validator doesn't appear to do anything in NestJS ...
In the ValidationPipe.transform method, it returns the raw input, because metatype is undefined: async transform(value, metadata) { const { ...
Read more >Fixing class-validator issues in a new Nest js project
So, I love the concept of DTO and I was trying to validate it using ValidationPipe , just like the doc says. It...
Read more >Building a REST API with NestJS and Prisma: Input Validation ...
A NestJS validation pipe will check the arguments passed to a route. ... You will now use the class-validator package to add validation ......
Read more >API payloads validation and transformation in NestJS - Medium
With NestJS ValidationPipe , handling several validations becomes much easier. ... We do this using decorators provided by the class-validator package, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You can start using forks now in the following way:
We’ll keep using the original packages for the time being till we figure out what’s the best approach to migrate.
It would be a breaking change to just swap out
class-validatorfor@nestjs/class-valdatorbecause there’s nothing in the update that would tell npm/yarn/pnpm that a new package would be necessary to download, so people updating package versions would now get this new error seemingly out of nowhere on a minor update. We could do a multi-step try/catch, i.e. try for@nestjs/class-validatorcatch tryclass-validatorcatch throw error, but the less optional package requires we have, usually the better (it’ll also mean needing to update our webpack config in nest-cli to exclude the@nestjs/class-validatorand@nestjs/class-transformerpackages).My plans would be to hold out until Nest v9 and have the forked package ready and maintained, and give instructions for how people could override the default if they wanted to, essentially making it opt-in until v9. Something like
Would be all that’s necessary to use this package (if it’s been published of course, I haven’t checked that part yet)