TypeScript is complex. JavaScript ecosystem is complex.
Most things can be done in may different ways, and things break and stop working all the time.
When ts-node has some issues, often tsx works. That is helpful.
But is it enough to "switch"?
Frequently Asked Questions | tsx
GitHub - privatenumber/ts-runtime-comparison: Comparison of Node.js TypeScript runtimes
TSX vs. TS-Node and Nodemon. Which NodeJS runner is fastest for… | by Lincoln W Daniel | ModernNerd Code | Medium
"I wanted tsx to be faster since it's so much simpler, but it unfortunately is not... "
- tsx is zero-config because it has smart detections built in. As a runtime, it detects what's imported to make many options in tsconfig.json redundant—which was designed for compiling matching files regardless of whether they're imported.
- It seamlessly adapts between CommonJS and ESM package types by detecting how modules are loaded (require() or import) to determine how to compile them. It even adds support for require()ing ESM modules from CommonJS so you don't have to worry about your dependencies as the ecosystem migrates to ESM.
- At the core, tsx is powered by esbuild for blazing fast TypeScript compilation, whereas ts-node (by default) uses the TypeScript compiler.
ts-node
incorporates type checking, tsx
does nottsx
handles package types automatically, ts-node
does not
node --import tsx
adds support for both Module and CommonJS contexts. To only import one, you can use node --import tsx/esm
or node --require tsx/cjs
.
node -r ts-node/register
only supports a CommonJS context, node --loader ts-node/esm
must be used for projects that are type Module.
"On average tsx
was faster, (about twice as fast on medium sized projects), than ts-node
. tsx
also includes a watch option which automatically reruns when the codebase is changed, which can be useful in certain circumstances.
Overall, it feels that losing type checking for a faster and more flexible runtime is a better choice ... for running tests and small dev scripts.