Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassSerializerInterceptor: .classToPlain is not a function #8637

Closed
3 of 15 tasks
c43721 opened this issue Nov 20, 2021 · 5 comments
Closed
3 of 15 tasks

ClassSerializerInterceptor: .classToPlain is not a function #8637

c43721 opened this issue Nov 20, 2021 · 5 comments
Labels
needs triage This issue has not been looked into

Comments

@c43721
Copy link

c43721 commented Nov 20, 2021

For those looking for a quick fix,

Downgrade to class-transformer: 0.4.0:

  • npm install class-transformer@0.4.0
  • yarn add class-transformer@0.4.0

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

When a controller uses ClassSerializerInterceptor, it will throw a TypeError: classTransformer.classToPlain is not a function due to a breaking change in the latest release https://github.com/typestack/class-transformer/blob/develop/CHANGELOG.md

Minimum reproduction code

https://github.com/nestjs/nest/tree/master/sample/21-serializer

Steps to reproduce

  1. Copy the Serializer example from Nestjs
  2. Run the application
  3. Make a request to a controller, see error.

Expected behavior

To serialize the data correctly.

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

class-serializer

NestJS version

8.2.2

Packages versions

"@nestjs/common": "^8.2.2"
"@nestjs/core": "^8.2.2"
"class-transformer": "^0.5.0"
"class-validator": "^0.13.2"

Node.js version

v16.6.1

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

The changes in class-validator have fixed the security vulnerabilities and have changed the names of the functions used. This should be patched asap, as this would benefit those who are not using the nestjs/class-transformer.

@c43721 c43721 added the needs triage This issue has not been looked into label Nov 20, 2021
@ahmedsaptan
Copy link

I have the same issue, when I try to add any validation I get this error.

@jmcdo29
Copy link
Member

jmcdo29 commented Nov 20, 2021

Downgrade to less than 0.5.0 for class-transformer. In your package.json you should be able to do "class-transformer": "<=0.4.0" as 0.4.1 was an accidental patch release for a major change

@ahmedsaptan
Copy link

thank you, it working now.

@Lobaton2020
Copy link

Thank you guys

apricote added a commit to apricote/Listory that referenced this issue Nov 21, 2021
@kamilmysliwiec
Copy link
Member

Let's track this here #8638

@nestjs nestjs locked and limited conversation to collaborators Nov 22, 2021
tiagojsag added a commit to Vizzuality/landgriffon that referenced this issue Nov 22, 2021
tiagojsag added a commit to Vizzuality/landgriffon that referenced this issue Nov 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs triage This issue has not been looked into
Projects
None yet
Development

No branches or pull requests

5 participants