How to use typia with tsx?
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 ?
No way, use ts-node instead.
https://github.com/TypeStrong/ts-node/issues/2133 😭
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"
}
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 :/
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.
No way, use
ts-nodeinstead.
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.
Asking for something that can't be done won't help anything.
Close this issue.
Asking for something that can't be done won't help anything.
Close this issue.
sure, for me not a big problem