Transformer ("class-transformer") metadata cannot be inherited for "X" class
julianpoemp opened this issue · comments
Is there an existing issue for this?
- I have searched the existing issues
Current behavior
I updated nestjs and other dependencies to the latest version and I get an error message as soon as I start serving the application:
ERROR [MappedTypes] Transformer ("class-transformer") metadata cannot be inherited for "AccountCreateRequestDto" class.
ERROR [MappedTypes] TypeError: Found non-callable @@iterator
previous, working installation:
├── @nestjs/cache-manager@2.1.0
├── @nestjs/common@10.2.5
├── @nestjs/config@3.1.1
├── @nestjs/core@10.2.5
├── @nestjs/jwt@10.1.1
├── @nestjs/mapped-types@2.0.2
├── @nestjs/passport@10.0.2
├── @nestjs/platform-express@10.2.5
├── @nestjs/schematics@10.0.2
├── @nestjs/serve-static@4.0.0
├── @nestjs/swagger@7.1.13
├── @nestjs/testing@10.2.5
├── @nestjs/throttler@4.2.1
├── @nestjs/typeorm@10.0.0
├── class-transformer@0.5.1
├── class-validator@0.14.0
current, failing installation:
├── @nestjs/cache-manager@2.1.1
├── @nestjs/common@10.2.10
├── @nestjs/config@3.1.1
├── @nestjs/core@10.2.10
├── @nestjs/jwt@10.2.0
├── @nestjs/mapped-types@2.0.4
├── @nestjs/passport@10.0.2
├── @nestjs/platform-express@10.2.10
├── @nestjs/schematics@10.0.3
├── @nestjs/serve-static@4.0.0
├── @nestjs/swagger@7.1.16 <-- error occurs with @nestjs/swagger >= 7.1.15
├── @nestjs/testing@10.2.10
├── @nestjs/throttler@5.0.1
├── @nestjs/typeorm@10.0.1
├── class-transformer@0.5.1
├── class-validator@0.14.0
AccountCreateRequestDto:
export class AccountCreateRequestDto extends PartialType(OmitType(AccountRegisterRequestDto, ['redirectTo'])) {
...
}
I'm using NodeJS 18 and Nx 17.0.3
Minimum reproduction code
https://github.com/julianpoemp/nestjs-swagger-issues
Steps to reproduce
Unfortunately, I wasn't able to reproduce the error in a minimum reproduction code.
- npm install
- npm start
Now the error should appear, but it doesn't. The project where the error appears is not public, I can't reference it.
Expected behavior
The error messages should disappear.
Package version
7.1.16
NestJS version
10.2.10
Node.js version
18.18.2
In which operating systems have you tested?
- macOS
- Windows
- Linux
Other
The error disappears when I downgrade @nestjs/swagger to 7.1.14. The other dependencies can be updated to the latest version.
Might be related to nestjs/mapped-types#1225 (comment) cc @KuanWenChen
But I will try to rewrite the code to minimize the impact on the package
@KuanWenChen yes, the repository I created to reproduce this issue doesn't trigger the error. I don't know why, but I know that this error occurs in my other (private) project and that it's solved when I downgrade @nestjs/swagger...
At the moment I don't know how to make this error reproducible. I'll keep trying...
@julianpoemp
I think I can't rollback something to mapped-type v2.0.2. It's going to cause _typeMetadatas, _exposeMetadatas, and _excludeMetadatas inherit incorrectly (Test Failed) .
If you have any case that could reproduce the problem, I would try to fix it.
Hi @KuanWenChen ! I managed to reproduce this error in this repository . In short the error is reproducible when you have something like this.
@Exclude()
export class UserPublicDto {
@Expose() @IsString()
username: string;
}
@Exclude()
export class UserDto extends UserPublicDto {
@Expose() @IsString()
password: string;
}
@Exclude()
export class UserUpdateDto extends OmitType(UserDto, ['password']) {
}
The OmitType is important here as well as that we are using it on a class which already extends from another class. This issue is not reproducible on 7.1.14
@YeritsyanTigran thank you very much for the reproduction!
@kamilmysliwiec
This problem cannot be reproduced in @nestjs/mapped-types@2.0.4. I think it has been fixed in mapped-types-issue-1225. The package dependency has not been updated to 2.0.4, as indicated here.
Is it solved or closed because it couldn't be reproduced?
It should be fixed in 7.1.17