rollup-plugin-esbuild

raw JSON →
6.2.1 verified Mon Apr 27 auth: no javascript

A Rollup plugin that uses esbuild for fast TypeScript/ESNext compilation and minification, replacing rollup-plugin-typescript2, @rollup/plugin-typescript, and rollup-plugin-terser. Current stable version is 6.2.1 (released Feb 2025), with active maintenance and releases every few months. Key differentiators: full esbuild integration (including JSX, define, loaders), built-in optimizeDeps for pre-bundling, standalone minify plugin, and support for Rollup 1-4. Requires esbuild >=0.18.0 and Rollup ^1.20.0 || ^2.0.0 || ^3.0.0 || ^4.0.0. Ships TypeScript types.

error Error: [plugin:esbuild] Transform failed with 1 error: <file>:<line>:<col>: ERROR: No loader is configured for ".vue" files
cause Plugin does not handle .vue files by default; custom loader needed.
fix
Add loaders: { '.vue': 'jsx' } or use a separate Vue plugin before esbuild.
error Cannot find module 'rollup-plugin-esbuild'
cause Missing installation or wrong import path in ESM/CJS context.
fix
Install with 'yarn add rollup-plugin-esbuild --dev' and ensure you use the correct import syntax for your module system.
error TypeError: esbuild is not a function
cause CommonJS require() on ESM-only package.
fix
Use dynamic import: const esbuild = (await import('rollup-plugin-esbuild')).default;
error Error: [plugin:esbuild] You must set the 'target' option to use the 'jsx' loader
cause Missing or invalid target when using JSX loader.
fix
Set a valid target like 'es2020' in plugin options or tsconfig.
error Error: [plugin:esbuild] 'define' must be an object with string values
cause define values must be string literals representing the replacement code.
fix
Use JSON.stringify for values: define: { __VERSION__: JSON.stringify('1.0.0') }
breaking v6.0.0 removed tsconfig resolution and the 'types' field. tsconfig will not be automatically resolved; you must pass 'tsconfig' option explicitly if needed.
fix Explicitly set tsconfig: 'tsconfig.json' in plugin options if you rely on tsconfig for JSX or target.
breaking v5.0.0 dropped Node.js <14 support and upgraded to Rollup v3. Users on older Rollup must upgrade.
fix Update Rollup to v3+ and Node.js to >=14.
breaking v6.2.0 added default loaders for .mjs, .cjs, .mts, .cts, .tsx, .jsx. This may cause conflicts if you already had custom loaders for these extensions.
fix Review loaders option to avoid duplicate mapping; set loaders explicitly if you want to override defaults.
deprecated The 'optimizeDeps' option is experimental and may break across minor versions.
fix Test thoroughly with each upgrade; consider alternative dep pre-bundling methods if stability is critical.
gotcha Plugin is ESM-only via default export. In CommonJS environments, you must use dynamic import().
fix Use async wrappers: const esbuild = (await import('rollup-plugin-esbuild')).default;
gotcha When using 'minify' standalone, esbuild may remove TypeScript type imports that are used only for types, causing dead code elimination.
fix Ensure type-only imports are side-effect-free; use 'import type' syntax.
npm install rollup-plugin-esbuild
yarn add rollup-plugin-esbuild
pnpm add rollup-plugin-esbuild

Shows how to use the esbuild plugin in a Rollup config with TypeScript, minification, define, and custom loaders.

// rollup.config.js
import esbuild from 'rollup-plugin-esbuild';

export default {
  input: 'src/index.ts',
  output: {
    file: 'dist/bundle.js',
    format: 'esm',
  },
  plugins: [
    esbuild({
      target: 'es2020',
      minify: true,
      define: {
        __VERSION__: JSON.stringify('1.0.0'),
      },
      loaders: {
        '.json': 'json',
      },
    }),
  ],
};