mapper icon indicating copy to clipboard operation
mapper copied to clipboard

Cannot determine type metadata Warning

Open lolekjohn opened this issue 3 years ago • 5 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Describe the issue

We are creating a lambda function (using nodejs typscript) and trying to implement the mapper logic. We took the sample implementation from the documentation web page

`import { classes, AutoMap } from '@automapper/classes'; import 'reflect-metadata'; import { createMapper, createMap, typeConverter, namingConventions, CamelCaseNamingConvention, forMember, mapFrom, } from '@automapper/core';

const mapper = createMapper({ strategyInitializer: classes(), namingConventions: new CamelCaseNamingConvention(), });

export class Job { @AutoMap() title!: string;

@AutoMap()
salary!: number;

}

export class Bio { @AutoMap(() => Job) job!: Job;

@AutoMap()
birthday!: Date;

@AutoMap()
avatarUrl!: string;

}

export class User { @AutoMap() firstName!: string;

@AutoMap()
lastName!: string;

@AutoMap()
username!: string;

password!: string; // <- we purposely left this one out because we don't want to map "password"

@AutoMap(() => Bio)
bio!: Bio;

}

export class BioDto { @AutoMap() jobTitle!: string;

@AutoMap()
jobSalary!: number;

@AutoMap()
birthday!: string;

@AutoMap()
avatarUrl!: string;

}

export class UserDto { @AutoMap() firstName!: string;

@AutoMap()
lastName!: string;

@AutoMap()
fullName!: string;

@AutoMap()
username!: string;

@AutoMap(() => BioDto)
bio!: BioDto;

}

createMap( mapper, Bio, BioDto, typeConverter(Date, String, (date) => date.toDateString()) );

createMap( mapper, User, UserDto, forMember( (d) => d.fullName, mapFrom((s) => s.firstName + ' ' + s.lastName) ) );

const user = new User(); user.firstName = 'Chau'; user.lastName = 'Tran'; user.username = 'ctran'; user.password = '123456'; user.bio = new Bio(); user.bio.avatarUrl = 'google.com'; user.bio.birthday = new Date(); user.bio.job = new Job(); user.bio.job.title = 'Developer'; user.bio.job.salary = 99999;

const dto = mapper.map(user, User, UserDto); console.log(user); console.log(dto); `

The response which we get is as below: `Cannot determine type metadata of "title" on class { }. "title" metadata has been skipped. Manually provide the "type" metadata to prevent unexpected behavior.

Cannot determine type metadata of "salary" on class { }. "salary" metadata has been skipped. Manually provide the "type" metadata to prevent unexpected behavior.

Cannot determine type metadata of "birthday" on class { }. "birthday" metadata has been skipped. Manually provide the "type" metadata to prevent unexpected behavior.

Cannot determine type metadata of "avatarUrl" on class { }. "avatarUrl" metadata has been skipped. Manually provide the "type" metadata to prevent unexpected behavior.

Cannot determine type metadata of "firstName" on class { }. "firstName" metadata has been skipped. Manually provide the "type" metadata to prevent unexpected behavior.

Cannot determine type metadata of "lastName" on class { }. "lastName" metadata has been skipped. Manually provide the "type" metadata to prevent unexpected behavior.

Cannot determine type metadata of "username" on class { }. "username" metadata has been skipped. Manually provide the "type" metadata to prevent unexpected behavior.

Cannot determine type metadata of "jobTitle" on class { }. "jobTitle" metadata has been skipped. Manually provide the "type" metadata to prevent unexpected behavior.

Cannot determine type metadata of "jobSalary" on class { }. "jobSalary" metadata has been skipped. Manually provide the "type" metadata to prevent unexpected behavior.

Cannot determine type metadata of "birthday" on class { }. "birthday" metadata has been skipped. Manually provide the "type" metadata to prevent unexpected behavior.

Cannot determine type metadata of "avatarUrl" on class { }. "avatarUrl" metadata has been skipped. Manually provide the "type" metadata to prevent unexpected behavior.

Cannot determine type metadata of "firstName" on class { }. "firstName" metadata has been skipped. Manually provide the "type" metadata to prevent unexpected behavior.

Cannot determine type metadata of "lastName" on class { }. "lastName" metadata has been skipped. Manually provide the "type" metadata to prevent unexpected behavior.

Cannot determine type metadata of "fullName" on class { }. "fullName" metadata has been skipped. Manually provide the "type" metadata to prevent unexpected behavior.

Cannot determine type metadata of "username" on class { }. "username" metadata has been skipped. Manually provide the "type" metadata to prevent unexpected behavior.

User { firstName: 'Chau', lastName: 'Tran', username: 'ctran', password: '123456', bio: Bio { avatarUrl: 'google.com', birthday: 2022-04-21T12:04:04.243Z, job: Job { title: 'Developer', salary: 99999 } } } UserDto { bio: BioDto {}, fullName: 'Chau Tran' }`

Models/DTOs/VMs

No response

Mapping configuration

No response

Steps to reproduce

No response

Expected behavior

User Dto object should be populated with all the mapper properties.

Screenshots

No response

Minimum reproduction code

No response

Package

  • [ ] I don't know.
  • [X] @automapper/core
  • [X] @automapper/classes
  • [ ] @automapper/nestjs
  • [ ] @automapper/pojos
  • [ ] @automapper/mikro
  • [ ] @automapper/sequelize
  • [ ] Other (see below)

Other package and its version

No response

AutoMapper version

8.0.0

Additional context

No response

lolekjohn avatar Apr 21 '22 12:04 lolekjohn

Can you make sure that you have reflect-metadata in the environment you're running? I've seen cases where reflect-metadata fails to get the information (because there's no information in the first place, eg: Vite)

nartc avatar May 04 '22 04:05 nartc

Can you make sure that you have reflect-metadata in the environment you're running? I've seen cases where reflect-metadata fails to get the information (because there's no information in the first place, eg: Vite)

I do have reflect-metadata package added to the Lambda function. Should that be enough?

lolekjohn avatar May 04 '22 04:05 lolekjohn

It should be enough yes. Is there a reproduce that you can share? I'm not familiar with AWS Lambda at all :(

nartc avatar May 04 '22 04:05 nartc

I had the same issue on the latest version too.

The error:

Cannot determine type metadata of "modes" on class UserVm.
"modes" metadata has been skipped.
Manually provide the "type" metadata to prevent unexpected behavior.

TouchSek avatar May 30 '22 08:05 TouchSek

if we try to use https://repl.it, we'll get the same error. See https://replit.com/@micalevisk/trying-automapper#index.ts

image

But I guess this is due to how Repl.it builds the project. In this case, I'm not sure if we could fix that even tho it works if we use automapper v7

micalevisk avatar Jun 03 '22 23:06 micalevisk