Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
The tsx npm package is a CLI tool for running TypeScript and TSX files directly without pre-compilation. It's essentially a TypeScript execution and REPL for node.js, similar to how `node` works for JavaScript. It allows developers to quickly run scripts and prototypes written in TypeScript, including support for TSX (TypeScript with JSX syntax), which is commonly used in React development.
Execute TypeScript files directly
Allows you to run a TypeScript file directly from the command line without needing to compile it first. This is particularly useful for quick scripts or during development.
tsx script.ts
REPL mode
Launches a REPL (Read-Eval-Print Loop) where you can type and execute TypeScript code interactively. This is useful for testing small snippets of code quickly.
tsx
Support for TSX
Enables execution of TSX files, which is TypeScript with JSX syntax. This is particularly useful for React developers who want to test components or scripts that include JSX.
tsx component.tsx
ts-node is a very popular package that offers similar functionality to tsx. It provides the ability to execute TypeScript files directly and use TypeScript in a REPL environment. ts-node is widely used in the TypeScript community for development and scripting. Compared to tsx, ts-node has been around longer and has a larger user base, but both aim to simplify the TypeScript development workflow by removing the compilation step.
esbuild-runner offers a way to run TypeScript (and JavaScript) files using the esbuild bundler/compiler. It's focused on providing extremely fast compilation and execution, leveraging esbuild's performance. While esbuild-runner and tsx share the goal of simplifying the execution of TypeScript files, esbuild-runner emphasizes speed and is part of the broader ecosystem around the esbuild project.
Node.js enhanced with esbuild to run TypeScript & ESM
.cjs
& .mjs
(.cts
& .mts
)node:
import prefixesnpm install --save-dev tsx
Install it globally to use it anywhere, outside of your npm project, without npx.
npm install --global tsx
Note: Commands are prefixed with
npx
to execute thetsx
binary, but it's not necessary if globally installed or when using it in thescript
object inpackage.json
Pass in a file to run:
npx tsx ./file.ts
Run file and automatically re-run on changes.
All imported files are watched except from the following directories:
node_modules
, bower_components
, vendor
, dist
, and .*
(hidden directories).
Press Return to manually re-run.
npx tsx watch ./file.ts
Start a TypeScript REPL by running tsx
with no arguments.
npx tsx
Modules transformations are cached in the system cache directory (TMPDIR
). Transforms are cached by content hash so duplicate dependencies are not re-transformed.
Set the --no-cache
flag to disable the cache:
npx tsx --no-cache ./file.ts
@esbuild-kit/esm-loader - Node.js Loader to transform TypeScript to ESM.
@esbuild-kit/cjs-loader - Node.js requie()
hook to transform TypeScript & ESM to CommonJS.
No, esbuild does not support type checking.
It's recommended to run TypeScript separately as a command (tsc --noEmit
) or via IDE IntelliSense.
tsx
different from ts-node
?They are both tools to run TypeScript files.
The main difference is that tsx
is powered by esbuild for blazing fast TypeScript compilation. Whereas ts-node
uses the TypeScript compiler, which is not as fast.
Because esbuild doesn't do type checking, tsx
is more equivalent to ts-node --transpileOnly
.
If you migrated from ts-node
, please share your performance gains here!
FAQs
TypeScript Execute (tsx): Node.js enhanced with esbuild to run TypeScript & ESM files
The npm package tsx receives a total of 2,209,325 weekly downloads. As such, tsx popularity was classified as popular.
We found that tsx demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.