samchon / nestia

NestJS Helper Libraries + TypeScript OpenAPI generator
https://nestia.io/
MIT License
1.85k stars 96 forks source link

How to use on Nest monorepo structure ? #916

Open fluffy-kaiju opened 5 months ago

fluffy-kaiju commented 5 months ago

Question

Hi! I need to use Nestia on a Nest project with monorepo structure. Sadly, I get this error after enable monorepo mode.

Error: Error on nestia.core.TypedRoute.Get(): no transform has been configured. Run "npx typia setup" command, or check if you're using non-standard TypeScript compiler like Babel or SWC.

Running npx typia setup don't help, by default, nest seems to use webpack [1] and the "plugin" [2] option is setup in tsconfig.json

// project-name-npm-mono/nest-cli.json:
...
  "compilerOptions": {
    "deleteOutDir": true,
    "webpack": true, // <<---- [1]
    "tsConfigPath": "apps/project-name-npm/tsconfig.app.json"
  },
...
// project-name-npm-mono/tsconfig.json:
...
    "plugins": [ // <<--- [2]
      {
        "transform": "@nestia/core/lib/transform",
        /**
         * Validate request body.
         * 
         *   - "assert": Use typia.assert() function
         *   - "is": Use typia.is() function
         *   - "validate": Use typia.validate() function
         *   - "assertEquals": Use typia.assertEquals() function
         *   - "equals": Use typia.equals() function
         *   - "validateEquals": Use typia.validateEquals() function
         */
        "validate": "assert",
        /**
         * Validate JSON typed response body.
         * 
         *   - "assert": Use typia.assertStringify() function
         *   - "is": Use typia.isStringify() function
         *   - "validate": Use typia.validateStringify() function
         *   - "stringify": Use typia.stringify() function, but dangerous
         *   - null: Just use JSON.stringify() function, without boosting
         */
        "stringify": "assert"
      },
      {
        "transform": "typia/lib/transform"
      }
    ],
...

I don't find any resource about using Nestia on monorepo, did I miss something ?

Here I've created a repo with the walkthrough of my test https://github.com/fluffy-kaiju/nestia-v3.2.1-nestjs-monorepo-issue

Thanks for your help :smile:

samchon commented 5 months ago

Currently, to make monorepo SDK generation working, you should generate SDK library per each package.

I'll study how to, but cannot sure to be succeeded.

honguyenhaituan commented 4 months ago

@fluffy-kaiju When use nestia you must compile your app by tsc and the default repo nestjs generate use webpack: true. So you have two way to make run correctly:

or create config webpack config use tsc as compiler and transpileOnly: false