samchon / typia

Super-fast/easy runtime validators and serializers via transformation
https://typia.io/
MIT License
4.62k stars 159 forks source link

How to use typia with tsx? #1265

Open victor314159 opened 2 months ago

victor314159 commented 2 months ago

Big fan of typia here, thanks for this amazing lib !

I'm trying to use typiawhen starting my backend in development mode with tsx

I use tsx because it allows very easy hot reloading when developping.

    "scripts": {
        "serve": "tsx watch ./lib/index.ts",
    },

Long story short, typia works fin in production mode (with tsc), but I don't know how to make it work with tsx

Is it possible ?

samchon commented 2 months ago

No way, use ts-node instead.

jairmedeiros commented 2 months ago

https://github.com/TypeStrong/ts-node/issues/2133 😭

victor314159 commented 2 months ago

This is how I fixed it:

 "serve": "tsx watch --inspect=0.0.0.0:9229 ./lib/index.ts", // stop using tsx
 "serve": "npx concurrently \"tsc --watch\" \"nodemon -L --inspect=0.0.0.0:9229 ./dist/index.js\"", // use tsc --watch option, so Typia works fine

because I'm running in a docker container, the node --watch wouldn't work, so I've used nodemon

Also added it to tsconfig.json (because tsc --wtach wouldn't work otherwise because of the container running on Windows.)

    "watchOptions": {
        "watchFile": "dynamicPriorityPolling"
    }
douglasg14b commented 1 month ago

ts-node has issues that tsx elegantly solves for. We use tsx almost exclusively due to compatibility & pipeline issues with ts-node which we had to drop support for after a good week of trying to use it.

It's unfortunate if the official stance is that tsx will never be supported because ts-node exists. Despite practical and longevity issues with ts-node 😥


Are there ways to work around this problem? We don't even necessarily need it with watch mode either.


When running vi tsx, we get:

'Internal Server Error: Error on typia.validate(): no transform has been configured. Read and follow https://typia.io/docs/setup please.',

Despite this setup already being completed.


Edit: Looks like TSX cannot use esbuild plugins . It uses esbuild internally, but cannot make use of plugins from the sound of it.

we can't because tsx uses esbuild's Transform API to process TypeScript, which doesn't support plugins.

Edit 2: https://github.com/privatenumber/pkgroll support might be a partial alternative or use case? Looks like it uses rollup and esbuild though :/

douglasg14b commented 1 month ago

Can we use this lib to instead codegen, and we can just consume that generated code with our normal build tools?

Edit: https://typia.io/docs/setup/#generation

Need a way to ass eslint ignores though, so many any errors.