typia icon indicating copy to clipboard operation
typia copied to clipboard

How to use typia with tsx?

Open victor314159 opened this issue 1 year ago • 5 comments

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 ?

victor314159 avatar Sep 08 '24 19:09 victor314159

No way, use ts-node instead.

samchon avatar Sep 08 '24 20:09 samchon

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

jairmedeiros avatar Sep 08 '24 22:09 jairmedeiros

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"
    }

victor314159 avatar Sep 09 '24 17:09 victor314159

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 avatar Sep 25 '24 20:09 douglasg14b

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.

douglasg14b avatar Sep 25 '24 21:09 douglasg14b

No way, use ts-node instead.

Following this reasoning, why use Typia? I can simply use native JSON.stringify.

The main issue is compatibility with tsx, as tsx is a tool that elegantly solves various problems. Adding support for it would be extremely useful.

Joaopaulovendramini avatar Mar 26 '25 12:03 Joaopaulovendramini

Asking for something that can't be done won't help anything.

Close this issue.

samchon avatar Mar 26 '25 14:03 samchon

Asking for something that can't be done won't help anything.

Close this issue.

sure, for me not a big problem

Joaopaulovendramini avatar Mar 26 '25 17:03 Joaopaulovendramini