Tsup TypeScript Bundler
Tsup is a zero-config TypeScript bundler powered by esbuild, designed to simplify bundling for JavaScript and TypeScript libraries. The current stable version is 8.5.1. While it previously had a regular release cadence with feature additions and bug fixes, the project is officially deprecated as of version 8.5.1.
Common errors
-
Error [ERR_REQUIRE_ESM]: require() of ES Module ...
cause Attempting to use an ES Module (ESM) output file from tsup in a CommonJS-only context or an older Node.js version that does not fully support ESM.fixEnsure your consuming environment fully supports ESM, or configure tsup to output CommonJS by specifying `--format cjs` in your build command or configuration. -
tsup: Missing peer dependency "typescript".
cause A required peer dependency, such as `typescript` or `@swc/core`, is not installed in your project's dependencies.fixInstall the missing peer dependency in your project's development dependencies, for example: `npm install typescript -D` or `yarn add typescript --dev`. -
[ERROR] Could not resolve "module-name" from "source-file.ts"
cause esbuild, the core bundler within tsup, failed to locate or resolve an imported module, often due to an incorrect path, missing dependency, or invalid `tsconfig.json` configuration.fixVerify the imported path for typos, ensure the module is correctly installed in `node_modules`, or check your `tsconfig.json` for correct `paths` aliases and `rootDir` configuration. -
Cannot find module 'tsup.config.ts'
cause Attempting to use a TypeScript configuration file (`tsup.config.ts`) directly without proper setup or with an older tsup version that didn't support it.fixEnsure you are using `tsup` version `8.3.0` or newer for `.cts` and `.mts` config file support. For `.ts` files, you might need a `ts-node` setup or transpile the config to JavaScript (`tsup.config.js`). -
SyntaxError: Cannot use import statement outside a module
cause This error can occur if your tsup configuration file is using ESM syntax (`import`/`export`) but is being interpreted as CommonJS, or vice-versa, without proper module configuration in `package.json`.fixEnsure your `tsup.config.js` file uses the appropriate module syntax for its context, or rename it to `tsup.config.mjs` for ESM or `tsup.config.cjs` for CommonJS if explicitly using module styles.
Warnings
- breaking This project is no longer actively maintained. Consider migrating to tsdown for continued support and updates.
- gotcha Tsup requires Node.js version 18 or higher to run correctly.
- gotcha A TypeScript version of 4.5.0 or higher is required as a peer dependency for tsup to function correctly.
- gotcha CSS support in tsup is experimental and may not be stable or fully featured. It might introduce unexpected behavior or breaking changes.
- gotcha The underlying esbuild dependency is updated frequently within tsup, which may lead to subtle changes in bundling behavior or require updates to esbuild-specific configuration options across minor tsup versions.
Install
-
npm install tsup -
yarn add tsup -
pnpm add tsup
Quickstart
npx tsup src/index.ts --format esm,cjs --dts