Skip to content

What is tsx?

tsx stands for TypeScript Execute, and it's a simple command to run TypeScript in Node.js.

tsx is basically an alias to node, so you can use it the same way:

sh
node file.js

sh
tsx file.ts

All Node.js command-line flags are supported—use tsx the same way you would use node!

Features

No hassle TypeScript runner

  • Just run TypeScript code. No configuration required!

    The primary goal of tsx is to run TypeScript code with modern and sensible defaults. This makes tsx very user-friendly and great for beginners!

CJS ↔ ESM interop

  • Seamlessly cross-import CommonJS and ES Modules!

    If you've encountered the following error in Node, you'll never see it again with tsx!

    Error [ERR_REQUIRE_ESM]: require() of ES Module <ESM package> from ./file.js not supported.
    Instead change the require of <ESM package> in ./file.js to a dynamic import() which is available in all CommonJS modules.

    This happens in Node.js when importing an ESM file from CommonJS, which can happen in new dependencies.

Watch mode

  • Iterate on your code faster and boost productivity!

    As a DX bonus, tsx comes with a watcher to re-run your files whenever you save them.

Limitations

TypeScript & ESM transformations are handled by esbuild, so it shares some of the same limitations such as:

For details, see esbuild's JavaScript caveats and TypeScript caveats documentation.