canirequire

canirequireDual (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.

Latest
4.23.13 (Aug 30, 2026)
Module format
Dual (CommonJS + ESM)
Last CommonJS version
4.23.13
Native ESM since
2.0.0
TypeScript types
Bundled
Node engines
>=18.0.0
Weekly downloads
61.9M
License
MIT

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.

Runtimerequire("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).

VersionsFormatFirst published
4.12.1 – 4.23.13Dual (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

Similar popularity