question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

class-validator not working nest-typescript-starter

See original GitHub issue

I’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:closed
  • Created 5 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

13reactions
jawad-aziz-farhadcommented, Jul 15, 2020

I thought its part of nestjs core but its not. Installing package separately solved this issue npm i class-validator --save

5reactions
luminbladecommented, Apr 28, 2018

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';

Read more comments on GitHub >

github_iconTop Results From Across the Web

class-validator not working nest-typescript-starter Code ... - Grepper
Answers related to “class-validator not working nest-typescript-starter”. nestjs typeorm · class-validator validate nested object · typescript get objects ...
Read more >
class-validator doesn't appear to do anything in NestJS ...
In my case the validations did not work as I did not have the class-transformer dependency in my application.
Read more >
How to use the class-validator.useContainer function in ... - Snyk
To help you get started, we've selected a few class-validator.useContainer examples, based on popular ways it is used in public projects.
Read more >
Validation · Bootstrap v5.0
Provide valuable, actionable feedback to your users with HTML5 form validation, via browser default behaviors or custom styles and JavaScript.
Read more >
Basic Features: TypeScript - Next.js
npm run dev # You'll see instructions like these: # # Please install TypeScript, @types/react, and @types/node by running: # # yarn add...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found