class-validator not working nest-typescript-starter
See original GitHub issueI’m submitting a…
[ ] Regression
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
class-validator not working
Expected behavior
class-validator should work
Minimal reproduction of the problem with instructions
Following the docs (https://docs.nestjs.com) untill the ‘pipes’ section (https://docs.nestjs.com/pipes). The pipes section creates a ValidationPipe. If you do not use this one, but try to use the ValidationPipe from the class-validator (npm install class-validator --save). The validation will not work.
@nestjs/common has a node_modules with the same dependency (class-validator). However if you do not install class-validator through npm, starting the application (npm start) will throw an error 'Cannot find module ‘class-validator’ '.
Workarounds:
- npm install class-validator --save to install the dependency, remove node_modules in @nestjs/common or
- npm install class-validator --save to install the dependency, do not remove node_modules in @nestjs/common but instead copy paste the installed class-validator from node_modules to your project files and reference to that directory as import
What is the motivation / use case for changing the behavior?
Removing the dependency from @nestjs/common would make it so that the project (following the docs) would work after installing the class-validator dependency.
Environment
Nest version:
"name": "nest-typescript-starter",
"version": "1.0.0"
"@nestjs/common": "^4.5.9",
"@nestjs/core": "^4.5.10",
"@nestjs/microservices": "^4.5.8",
"@nestjs/testing": "^4.5.5",
"@nestjs/websockets": "^4.5.8",
For Tooling issues:
- Node version: v9.11.1
- Platform: Linux
Others:
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (2 by maintainers)
Top GitHub Comments
I thought its part of nestjs core but its not. Installing package separately solved this issue
npm i class-validator --save
There is a ticket open for this on the class-validator site.
link
my workaround (for now) is to import the same library
import { IsInt, IsString } from '@nestjs/common/node_modules/class-validator';