'@nestjs/swagger cant be used with angular
We have a monorepo with nestjs, angular and libs. In one of those libs we defined all DTOs and some of them use mapped-types from @nestjs/swagger like OmitType or PickType:
export class UserDTOCreation extends PickType(UserDTO, ['username', 'password']){}
It is fine to use these DTOs in Angular as types like:
const user: UserDTOCreation = {} as never;
The lib will not be included into the angular build.
Now it would also be nice to be able to use class-transformer in the frontend so that date strings sent over the network will be transformed back to Date objects and stuff like that. But once you use plainToClass(UserDTO, dto) from class-transformer, the DTOs are not just imported as types anymore and therefore the whole DTO lib is required for the angular build including @nestjs/swagger and its dependencies.
Upon building angular there are a lot of errors like this: build errors
Apperently this is because there are now some node dependencies required that don't exist in the browser.
How to fix this? I wouldn't want to include all of those polyfills and I havent found any information on where to configure resolve.fallback: { "path": false } I guess for the mapped-type functionality the node dependencies aren't even required.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
