nestia icon indicating copy to clipboard operation
nestia copied to clipboard

How to use on Nest monorepo structure ?

Open fluffy-kaiju opened this issue 1 year ago • 2 comments

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:

fluffy-kaiju avatar Jun 16 '24 21:06 fluffy-kaiju

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.

samchon avatar Jun 20 '24 03:06 samchon

@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:

  • turn off webpack
// project-name-npm-mono/nest-cli.json:
...
  "compilerOptions": {
    "deleteOutDir": true,
    "webpack": false, // <<---- [1]
    "tsConfigPath": "apps/project-name-npm/tsconfig.app.json"
  },
...

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

honguyenhaituan avatar Jul 10 '24 14:07 honguyenhaituan

Upgrade to v7.2, then be solved.

samchon avatar Jul 16 '25 17:07 samchon