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.

TypeError: Cannot read property 'prototype' of undefined

See original GitHub issue

Error appears here: https://github.com/typestack/class-validator/blob/master/src/metadata/MetadataStorage.ts#L79

Everything is quiet ordinar. I have this class for validation:

export class RegisterMasterBody {
  @IsEmail()
  email: string;

  @MinLength(6)
  password: string;

  name: string;

  instagram?: string;

  description?: string;

  lat?: number;

  long?: number;
}

And here how I check for errors:

@Post()
  @Render("register")
  public async register(@Res() res: Response, @Body() body: RegisterMasterBody) {
    try {
      console.log(body, typeof body, body.constructor);
      const errors = await validate(body, { skipMissingProperties: true });
      console.log(errors, "errors of validate");
    } catch (error) {
      console.error(error, "POST REGISTER");
    }
  }

in console.log typeof body - “object”, constructor undefined

But inside here Error appears here: https://github.com/typestack/class-validator/blob/master/src/metadata/MetadataStorage.ts#L79 metadata.target is RegisterMasterBody

I tried to gather as much info as I can, since this is another project full of everything to strip it down and create repo with isolated reproduction 😦

Class validator is the same version as in this repo.

edit: worth mention - there are more properties that do not belong to RegisterMasterBody coming in request. But I tried adding them to RegisterMastBody - did not help

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
theobouwmancommented, May 13, 2018
[Nest] 77719   - 2018-5-13 22:27:55   [ExceptionsHandler] Cannot read property 'prototype' of undefined
TypeError: Cannot read property 'prototype' of undefined
    at /Users/theobouwman/dev/projects/webshop_top/src/metadata/MetadataStorage.ts:79:37
    at Array.filter (<anonymous>)
    at MetadataStorage.getTargetValidationMetadatas (/Users/theobouwman/dev/projects/webshop_top/src/metadata/MetadataStorage.ts:75:61)
    at ValidationExecutor.execute (/Users/theobouwman/dev/projects/webshop_top/src/validation/ValidationExecutor.ts:44:54)
    at Validator.coreValidate (/Users/theobouwman/dev/projects/webshop_top/src/validation/Validator.ts:31:18)
    at Validator.validate (/Users/theobouwman/dev/projects/webshop_top/src/validation/Validator.ts:56:21)
    at Object.validate (/Users/theobouwman/dev/projects/webshop_top/src/index.ts:49:44)
    at ResellerBrandArticleController.newArticlePost (/Users/theobouwman/dev/projects/webshop_top/src/controllers/reseller.brand.article.controller.ts:28:5)
    at RouterExecutionContext.<anonymous> (/Users/theobouwman/dev/projects/webshop_top/node_modules/@nestjs/core/router/router-execution-context.js:52:33)
    at Generator.next (<anonymous>)

Same error here.

This is my code:

import {IsNumber, MaxLength, MinLength} from 'class-validator';

export class NewArticleDto {
  @MinLength(3)
  readonly name: string;

  @MinLength(10)
  @MaxLength(500)
  readonly description: string;

  @IsNumber()
  readonly price: number;

  @IsNumber()
  readonly stock: number;
}
0reactions
lock[bot]commented, Oct 16, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix Uncaught TypeError: Cannot read property ' ...
I fixed this bug. The problem was that I created Collection and then the Model. Collections use user model, as working unit, ...
Read more >
TypeError: Cannot read property 'prototype' of undefined · ...
I've come across a TypeError of which I can't seem to find the cause though. Does anyone have an idea where I should...
Read more >
exception cannot read property 'prototype' of undefined
So the audit relationship is missing? The relationship is generated automatically when you check the Audited box on any object field. An Audit_< ......
Read more >
Cannot read property 'prototype' of undefined
Hi, how do I resolve konyuiBaseClasses.js:4 Uncaught TypeError: Cannot read property 'prototype' of undefined. The problem is I can't load ...
Read more >
Uncaught TypeError: Cannot read property 'prototype' of ...
This issue happens when a subtheme has not been updated to extend the Bootstrap/framework library. on the linked issues. I marked the priority ......
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