DEV Community

Dan Muntean
Dan Muntean

Posted on

Getting an error when using @ValidateNested decorator in NestJs

Hi, I'm working on an backend application which is using NestJs framework. Recently I updated the libraries and the class-validator library from 0.14.0 to 0.14.1 and mongo library from 6.0.0 to 6.5.0.
After this update I am getting this error when trying to validate an array of ObjectId.

[Nest] 60017 - 04/22/2024, 1:07:48 PM ERROR Error [ERR_INTERNAL_ASSERTION]: Error: BSONError: Cannot create Buffer from undefined
at Object.toLocalBufferType
at Object.toHex
at ObjectId.toHexString
at ObjectId.inspect
at ObjectId.[nodejs.util.inspect.custom]
at formatValue (node:internal/util/inspect:782:19)
at formatProperty (node:internal/util/inspect:1819:11)
at formatArray (node:internal/util/inspect:1645:17)
at formatRaw (node:internal/util/inspect:1027:14)
at formatValue (node:internal/util/inspect:817:10)
This is caused by either a bug in Node.js or incorrect usage of Node.js internals.
Please open an issue with this stack trace at

@ApiProperty({ type: [ObjectId], required: false })
  @Transform(Transformers.objectIdJSONTransformer, {
    toClassOnly: true,
  @ValidateNested({ each: true })
  @Type(() => ObjectId)
  podsIds?: ObjectId[];
Enter fullscreen mode Exit fullscreen mode

Need to mention that the @ValidateNested decorator is working on other validations which are objects. Thank you!

Top comments (0)