Installation
Install tsx in a project for a shared, repeatable setup, or globally for commands used across directories. These are alternatives; a project installation does not need a global one.
You need Node.js and a package manager on your PATH. See compatibility for supported versions. For a first runnable example, follow Getting started.
Project installation
For development scripts, install tsx as a development dependency. This records the dependency in package.json so other contributors can install it too.
If you are starting in an empty directory, create package.json first with your package manager's initialization command, such as npm init -y or pnpm init.
Run one of these commands in the directory containing your project's package.json, using your project's package manager:
npm install -D tsxpnpm add -D tsxyarn add -D tsxUsing tsx
In your project directory, add this file:
script.ts
console.log('Hello from tsx!')Run the installed executable through your package manager:
npx tsx ./script.tsIt prints:
Hello from tsx!Using it in package.json#scripts
To give the command a name, add a start entry to the scripts object in package.json. Keep any other fields and scripts your project already has.
Package scripts can reference the locally installed tsx directly:
package.json (merge this entry into your existing scripts)
{
"scripts": {
"start": "tsx ./script.ts"
}
}Run the script with your package manager:
npm run startpnpm run startyarn run startThe package manager may print a command header, followed by the script output:
Hello from tsx!Global installation
Global installation makes the tsx executable available across directories. It does not record tsx as a project dependency.
npm install -g tsxpnpm add -g tsxYarn 2 and later do not support global installation. Use project installation, or see Yarn's guidance on yarn dlx for running a package without adding it to a project.
With the global package manager's executable directory on your PATH, you can call tsx directly. From the directory containing script.ts, run:
tsx ./script.tsIt prints:
Hello from tsx!Troubleshooting
tsx: command not found: usenpx tsxinside a project installation, or check that your global package manager's executable directory is onPATH.- An install prompt when using
npx: the package is not installed in the current project. Install dependencies and run the command from that project's directory. - Missing tsx after deployment: development dependencies may have been omitted. If your application executes through tsx in production, declare it as a runtime dependency; see deployment choices.
