2

Recently, we started a new project with Angular and NestJS inside a monorepo Nx, and it works great. However, when we want to use @nestjs/swagger features inside a shared lib called "DTO", things start to break.

Firstly, Angular didn't compile anymore. Hopefully, I found a good Stackoverflow post covering this subject and followed the recommandation: create a webpack config to shim out the @nestjs/swagger package with Angular builder (Source: Post Stackoverflow)

Here is the custom webpack config:

import path from 'path';

export default function customConfig(config: any) {
    return {
        ...config,
        resolve: {
            ...config.resolve,
            alias: {
                ...config.resolve.alias,
                // shims out nestjs swagger module in the frontend for DTO sharing
                '@nestjs/swagger': path.resolve(
                    __dirname,
                    '../../node_modules/@nestjs/swagger/dist/extra/swagger-shim'
                ),
            },
        },
    };
}

And now, it compiles ! 🥳

But, some days later, I have another small problem: I'm unable to use PartialType, OmitType,... all the mapped-types described here: Mapped Types NestJS/Swagger

The error when the DTO is loaded: TypeError: Class extends value () =\> {} is not a constructor or null

And it points to this DTO: export class UpdateSpireDto extends PartialType(CreateSpireDto) {}

Once I remove the extends PartialType method, it works correctly.

Does anyone have an idea how to resolve this ?

Or any recommandation of how to share DTO/models/... Between frontent (Angular) and backend (NestJS) inside Nx ?

I already considered to remove the PartialType method and use only the class with the properties, but it is not a good idea in a long term project. Using these mapped-types would be a great advantage for us.

I've already looked to these posts:

How to use NX DTO libraries decorated with NestJS swagger api in frontend frameworks

How to enable Swagger for API interfaces shared between NestJS and Angular within Nx monorepo?

But my problem does not come from the nestjs decorators, only the methods mapped-types...

Thank you in advance and have a nice day !

1 Answer 1

0

Hi @Nxtivision I'v run today with the same issue.

For me it helped to update from "@nestjs/swagger": "7.1.1" to "@nestjs/swagger": "7.3.0".

I hope it helps You also.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.