Linux command
tsx 命令
网络
复制后可按需替换文件名、目录或参数。
常用示例
Run a TypeScript file
tsx [script.ts]
Run with watch mode
tsx watch [script.ts]
Start TypeScript REPL
tsx
Run as Node.js loader
node --import tsx [script.ts]
Run with environment variables
tsx [script.ts] --env-file [.env]
Pass arguments to script
tsx [script.ts] -- [arg1] [arg2]
说明
tsx (TypeScript Execute) is an enhanced Node.js runtime that seamlessly runs TypeScript and ESM files. It uses esbuild for fast transpilation, making it ideal for development and scripting. The tool requires zero configuration and works without a tsconfig.json file. It supports both CommonJS and ES modules, handles path aliases from tsconfig.json, and includes a watch mode for development. tsx is a drop-in replacement for node, supporting all Node.js command-line flags. It transpiles TypeScript on-the-fly without writing JavaScript files to disk. Note that tsx focuses on execution speed and does not perform type checking. Use tsc or your editor for type checking. Install globally: `npm install -g tsx`
参数
- watch
- Watch mode: restart on file changes.
- --tsconfig _file_
- Path to tsconfig.json file.
- --env-file _file_
- Load environment variables from file.
- --no-cache
- Disable transform caching.
- --help
- Display help information.
- --version
- Display version information.
FAQ
What is the tsx command used for?
tsx (TypeScript Execute) is an enhanced Node.js runtime that seamlessly runs TypeScript and ESM files. It uses esbuild for fast transpilation, making it ideal for development and scripting. The tool requires zero configuration and works without a tsconfig.json file. It supports both CommonJS and ES modules, handles path aliases from tsconfig.json, and includes a watch mode for development. tsx is a drop-in replacement for node, supporting all Node.js command-line flags. It transpiles TypeScript on-the-fly without writing JavaScript files to disk. Note that tsx focuses on execution speed and does not perform type checking. Use tsc or your editor for type checking. Install globally: `npm install -g tsx`
How do I run a basic tsx example?
Run `tsx [script.ts]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does watch do in tsx?
Watch mode: restart on file changes.