Registry / devops / esbuild-plugin-babel-cjs

esbuild-plugin-babel-cjs

JSON →
library1.0.0jsnpmunverified

A CommonJS-compatible Babel plugin for esbuild. Current stable version 1.0.0. This plugin allows you to apply Babel transformations within esbuild bundles when esbuild's native transform capabilities are insufficient. Unlike alternatives (e.g., esbuild-plugin-babel or @aspect-build/esbuild), this package explicitly targets CommonJS environments and provides a simple, minimal API. It requires @babel/core as a peer dependency and delegates Babel configuration to babel.config.json or inline config. Suitable for legacy projects or those locked into CJS.

npm install esbuild-plugin-babel-cjs
INSTALL
IMPORT
SIG · ESBUILD-PLUGIN-BAB
E
esbuild-plugin-babel-cjs
devopsjavascriptv1.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

plugin (default)
const babel = require('esbuild-plugin-babel-cjs');
const babel = require('esbuild-plugin-babel-cjs').default;
Package uses CommonJS default export; require directly returns the plugin function.
plugin (ESM)
import babel from 'esbuild-plugin-babel-cjs';
import { babel } from 'esbuild-plugin-babel-cjs';
Default import works because the module has a default export that resolves to the plugin function.
TypeScript types
import type { BabelPluginConfig } from 'esbuild-plugin-babel-cjs';
import { BabelPluginConfig } from 'esbuild-plugin-babel-cjs';
Type imports are available for config interface. Named type import is correct.

Minimal esbuild config that applies Babel transformations via the plugin. Ensure @babel/core is installed and Babel configuration is set separately.

const esbuild = require('esbuild'); const babel = require('esbuild-plugin-babel-cjs'); esbuild.build({ entryPoints: ['index.js'], bundle: true, outfile: 'main.js', plugins: [babel()], }).catch(() => process.exit(1));
Debug
Known issues
gotchaPlugin does not apply any transforms by default: you must provide a Babel config via babel.config.json or the 'config' option. Without one, Babel runs as a no-op.
fix
Create a babel.config.json or pass config object to babel({ config: { presets: [...], plugins: [...] } }).
affects: >=1.0.0
gotchaIf targeting es5, esbuild must also have target: ['es5'] set; otherwise esbuild will output modern syntax first and Babel may not produce valid es5.
fix
Add target: ['es5'] to esbuild.build options.
affects: >=1.0.0
deprecatedThe package README references esbuild-plugin-babel (without cjs) in the example code (line: const babel = require('esbuild-plugin-babel');). This is a copy-paste error; the correct package is esbuild-plugin-babel-cjs.
fix
Replace require('esbuild-plugin-babel') with require('esbuild-plugin-babel-cjs').
affects: ==1.0.0
gotchaPlugin uses a synchronous transform under the hood; large files or complex Babel presets may cause performance issues or blocking in esbuild's async pipeline.
fix
Consider using esbuild's own transforms when possible for performance.
affects: >=1.0.0
gotchaThe plugin namespace option defaults to an empty string, which may conflict with other plugins. Use a specific namespace like 'babel' to isolate.
fix
Pass babel({ namespace: 'babel' }) to avoid conflicts.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module '@babel/core'
@babel/core is not installed or is missing from node_modules.
fix
Run 'npm install @babel/core --save-dev' or add it to devDependencies.
Error: Callback must be a function. Received undefined
Attempting to import a non-existent named export (e.g., import { babel } from 'esbuild-plugin-babel-cjs').
fix
Use default import: import babel from 'esbuild-plugin-babel-cjs' or require('esbuild-plugin-babel-cjs').
Error: No Babel configuration found
No babel.config.json, .babelrc, or inline config provided.
fix
Create a babel.config.json in the project root or pass config option to babel().
ReferenceError: require is not defined
Using require() in an ESM context (e.g., 'type':'module' in package.json).
fix
Use import syntax: import babel from 'esbuild-plugin-babel-cjs';
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
@babel/coreoptionalPeer dependency - required to run any Babel transformations.
Agent activity
4 hits · last 30 days
node
4
Resources
esbuild-plugin-babel-cjs — npm install esbuild-plugin-babel-cjs · libregistry