esbuild-plugin-babel-cached
raw JSON → 0.2.3 verified Sat Apr 25 auth: no javascript
esbuild-plugin-babel-cached (v0.2.3) is an esbuild plugin that runs files through Babel for transforms not supported natively by esbuild, with built-in caching. It wraps @babel/core and allows configuration via babel.config.json or inline options. Unlike other esbuild Babel plugins, it caches results to speed up rebuilds. The plugin is stable with weekly releases and is intended for scenarios where esbuild's own transforms (e.g., newer JavaScript/TypeScript) are insufficient and you need Babel for specific presets or plugins (e.g., for legacy browser support or custom transforms). It depends on @babel/core as a peer dependency and is ESM-only.
Common errors
error Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/esbuild-plugin-babel-cached/index.js from /path/to/project/esbuild.config.js not supported. ↓
cause Using CommonJS require() with an ESM-only package.
fix
Convert config file to ES module: rename to .mjs or add "type": "module" in package.json. Then use: import babel from 'esbuild-plugin-babel-cached'
error TypeError: (0 , _default) is not a function ↓
cause Named import instead of default import.
fix
Use: import babel from 'esbuild-plugin-babel-cached' (no curly braces)
error Error: Cannot find module '@babel/core' ↓
cause Missing peer dependency @babel/core.
fix
Install: npm install @babel/core -D
Warnings
breaking The plugin is ESM-only and cannot be loaded via require(). ↓
fix Use ES module imports (import babel from ...) and set "type": "module" in package.json or use .mjs extension.
deprecated The `config` option accepts Babel configuration; placing options in babel.config.json is also supported, but inline config takes precedence. ↓
fix If using babel.config.json, ensure it is in the project root or set rootMode: 'upward' in config.
gotcha If you target es5 with esbuild's own target option, Babel may not transform output if esbuild already handles it; ensure the Babel plugin runs before esbuild's internal transforms. ↓
fix Set esbuild target to the desired output (e.g., 'es5') to let esbuild handle what it can, and use Babel for additional transforms that esbuild doesn't support.
gotcha Caching may cause stale results if Babel config changes; clear cache by deleting node_modules/.cache/esbuild-plugin-babel-cached or setting CACHE_DIR environment variable. ↓
fix Set process.env.CACHE_DIR to a temporary directory or disable caching by passing cache: false to babel() options.
Install
npm install esbuild-plugin-babel-cached yarn add esbuild-plugin-babel-cached pnpm add esbuild-plugin-babel-cached Imports
- babel wrong
const babel = require('esbuild-plugin-babel-cached')correctimport babel from 'esbuild-plugin-babel-cached' - babel wrong
import { babel } from 'esbuild-plugin-babel-cached'correctimport babel from 'esbuild-plugin-babel-cached' - plugin type (TypeScript)
import type { Plugin } from 'esbuild'; import babel from 'esbuild-plugin-babel-cached'; const plugin: Plugin = babel();
Quickstart
import esbuild from 'esbuild';
import babel from 'esbuild-plugin-babel-cached';
await esbuild.build({
entryPoints: ['src/index.ts'],
bundle: true,
outfile: 'dist/bundle.js',
plugins: [babel({
filter: /\.(js|ts)$/,
config: {
presets: ['@babel/preset-env'],
plugins: ['@babel/plugin-transform-arrow-functions']
}
})],
target: ['es5']
});