Skip to content

Frequently Asked Questions

How can I do ______ in tsx?

We understand that searching for answers about tsx can be challenging due to its name. However, since tsx is essentially an alias for node and adheres to TypeScript behavior, asking how to do something in tsx might not be the best approach.

Instead, consider these questions:

  • "How can I do ______ in Node.js?"
  • "How can I do ______ in TypeScript?"

If your question specifically relates to tsx, you can use the search feature in the documentation or ask a question.

I found a bug in tsx. What should I do?

If you've confirmed that the bug is in tsx, please file an issue in the tsx GitHub repository. Make sure to include a minimal reproduction of the bug.

File a bug report ↗

Who uses tsx?

tsx is recognized by both Node.js and TypeScript as a popular tool for running TypeScript code. It is widely adopted, as indicated by its npm download stats: .

Companies

VercelGoogleGitHubSquareSupabaseAstroOpenAIIBMCodecovAmazon AWSSentryMicrosoftMetaAlibabaMozillaFigmaCloudflareSalesforce

Projects

Node.jsElectronViteMermaidVue.js11tyVitestdate-fnsCheerioZodWebDriverIOKnipArkTypePrisma

To find more examples of where & how tsx is used, search on GitHub.

How does tsx compare to ts-node?

tsx and ts-node are both tools for running TypeScript in Node.js, each offering different approaches to suit user preferences.

Installation

  • tsx: Can be used without installation (via npx tsx ./script.ts) and comes as a single binary with no peer dependencies.
  • ts-node: Requires installation of TypeScript or SWC as peer dependencies.

Configuration

  • tsx: Works out of the box without needing a tsconfig.json file, making it easy for beginners.
  • ts-node: May require initial setup and configuration.

Defaults

  • tsx: Uses sensible defaults based on file imports and Node.js version, reducing the need for certain tsconfig.json settings.
  • ts-node: Relies on TypeScript's defaults, which might need adjusting.

Module Support

  • tsx: Automatically adapts between CommonJS and ESM modules, supporting require() for ESM modules.
  • ts-node: Provides module support but may need configuration for certain scenarios.

Syntax and Features

  • tsx: Supports new JS & TS syntax and features based on Node.js version and includes support for tsconfig.json paths.
  • ts-node: Uses the TypeScript compiler and may require additional settings for certain features.

Speed

  • tsx: Uses esbuild for fast compilation and does not perform type checking.
  • ts-node: Uses the TypeScript compiler by default, with an option to use the SWC compiler for faster performance.

Watcher

As a DX bonus, tsx also comes with Watch mode to help you iterate faster!

For a detailed technical comparison, refer to this exhaustive comparison between tsx, ts-node, and other runtimes.

Can/should tsx be used in production?

Deciding whether to use tsx in production depends on your specific needs and risk tolerance. Here are a few points to consider:

  • tsx is simply a Node.js enhancement, so you can generally expect a similar level of stability.
  • tsx uses esbuild for transforming TypeScript and ESM. Although esbuild is already adopted in many production ready tools, keep in mind that it technically hasn't reached a stable release yet.

Here are some questions to help guide your decision:

  • What are the benefits versus the costs of using tsx in production? Are there performance improvements?
  • Does tsx run your code as expected? Are there any differences between development and production environments?
  • Can you rely on this open-source project and its maintainers? Consider sponsoring the project to support its growth and stability.

Ultimately, it's a decision you'll need to make based on your specific production requirements and comfort level with potential risks.


Ask a question

tsx offers support via Discussions for sponsors. If you're a sponsor, feel free to ask more questions there!