canirequire › Dual (CommonJS + ESM) › tsx
Is tsx ESM-only? Can you require() it?
TypeScript Execute (tsx): Node.js enhanced with esbuild to run TypeScript & ESM files
Last verified Sep 9, 2026 against tsx@4.23.13. JSON
Dual (CommonJS + ESM) Dual package — both require() and import work
tsx publishes both a CommonJS entry and a native ESM entry (ESM added in 2.0.0). require("tsx") and import "tsx" both work on every supported Node.js version and in Bun.
Does tsx@4.23.13 actually load? Runtime test results
Installed and executed on Sep 9, 2026 with require("tsx") from a CommonJS file and import "tsx" from an ES module.
| Runtime | require("tsx") | import "tsx" |
|---|---|---|
| Node.js 18 | ✗ failsERR_REQUIRE_ESM | ✓ works |
| Node.js 20 | ✓ works | ✓ works |
| Node.js 22 | ✓ works | ✓ works |
| Node.js 24 | ✓ works | ✓ works |
| Node.js 26 | ✓ works | ✓ works |
| Bun 1.4 | ✗ failserror: Cannot find module './cjs/index.cjs' from '' | ✗ failserror: Cannot find module './cjs/index.cjs' from '' |
A failing require() on a CommonJS package usually means the package needs a browser/DOM global, a peer dependency, or a native binary that is not available in a bare Node.js process.
How to import tsx
ES modules (import)
import tsx from "tsx";CommonJS (require)
const tsx = require("tsx");Module format by version
Derived from the type, main and exports fields of every stable release on npm (140 versions; the newest 60 shown).
| Versions | Format | First published |
|---|---|---|
| 4.12.1 – 4.23.13 | Dual (CommonJS + ESM) | Jun 7, 2024 |
Frequently asked
Is tsx ESM-only?
tsx@4.23.13 ships CommonJS and ESM builds. tsx publishes both a CommonJS entry and a native ESM entry (ESM added in 2.0.0). require("tsx") and import "tsx" both work on every supported Node.js version and in Bun.
Can I require tsx?
Yes. tsx ships a CommonJS entry, so require("tsx") works on every Node.js version, alongside the native ESM entry for import.
Does tsx work in Bun?
Importing tsx failed in Bun 1.4 on Sep 9, 2026: error: Cannot find module './cjs/index.cjs' from ''
Does tsx ship TypeScript types?
Yes. tsx bundles its own type declarations; no @types package is needed.
Links
Other dual (commonjs + esm) packages
- minimatch 10.2.6Dual
- brace-expansion 5.0.9Dual
- lru-cache 11.5.2Dual
- glob 13.0.6Dual
- eslint-visitor-keys 5.0.1Dual
- yallist 5.0.0Dual
- balanced-match 4.0.4Dual
- js-yaml 5.4.1Dual
Similar popularity
- @babel/helper-optimise-call-expression 8.0.0ESM-only
- tinybench 6.1.6ESM-only
- eastasianwidth 0.3.0CommonJS
- lodash.isplainobject 4.0.6CommonJS
- core-js 3.50.0CommonJS
- destroy 1.2.0CommonJS
- ajv-keywords 5.1.0CommonJS
- xtend 4.0.2CommonJS