Nest: Dependency not being included in @nestjs/common

Created on 28 Sep 2020  路  2Comments  路  Source: nestjs/nest

Bug Report

related to #4954

Current behavior

When importing ValidationPipe from @nestjs/common the console throws this message on runtime:


The "class-transformer" package is missing. Please, make sure to install this library ($ npm install class-transformer) to take advantage of ValidationPipe.

and


The "class-validator" package is missing. Please, make sure to install this library ($ npm install class-validator) to take advantage of ValidationPipe.

Expected behavior

Since _ValidationPipe_ is being imported from a "common" module, shouldn't it be built into it? If not, why?

Also, there's no hint in the documentation that relates the class-validator and class-transformer dependencies with _ValidationPipe_ (as they are required for ValidationPipe to work)

Possible Solution

These libraries should be included natively since _ValidationPipe_ belongs to @nestjs/common

Environment


Nest version: 7.5.1

For Tooling issues:

  • Node version: v12.16.1
  • Platform: macOS
needs triage

Most helpful comment

No documentation the pipe uses them:

Because this pipe uses the class-validator and class-transformer libraries, there are many options available. You configure these settings via a configuration object passed to the pipe. Following are the built-in options

Found here in the docs

The pipe usage is optional, and to keep the @nestjs/common package smaller, these classes are not directly installed. The same goes for @nestjs/microservices, @nestjs/websockets, @nestjs/platform-fastify, and @nestjs/platform-express (though the last one is installed by default from the CLI).

These are all optional dependencies depending on your server's set up, so they should not be included with the package.

There _could_ be an added note in the docs however about installing the libraries manually, as it is necessary, but other than that, the libraries should not be added, in an attempt to keep the @nestjs/common package smaller.

All 2 comments

No documentation the pipe uses them:

Because this pipe uses the class-validator and class-transformer libraries, there are many options available. You configure these settings via a configuration object passed to the pipe. Following are the built-in options

Found here in the docs

The pipe usage is optional, and to keep the @nestjs/common package smaller, these classes are not directly installed. The same goes for @nestjs/microservices, @nestjs/websockets, @nestjs/platform-fastify, and @nestjs/platform-express (though the last one is installed by default from the CLI).

These are all optional dependencies depending on your server's set up, so they should not be included with the package.

There _could_ be an added note in the docs however about installing the libraries manually, as it is necessary, but other than that, the libraries should not be added, in an attempt to keep the @nestjs/common package smaller.

Hmm. Now I understand the philosophy and you're right. I generated the issue because the previous answers wasn't clear. Anyway thanks for the explanation.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hackboy picture hackboy  路  3Comments

rlesniak picture rlesniak  路  3Comments

cojack picture cojack  路  3Comments

2233322 picture 2233322  路  3Comments

tronginc picture tronginc  路  3Comments