{"id":25314,"library":"esbuild-plugin-babel-cjs","title":"esbuild-plugin-babel-cjs","description":"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.","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/nleclerc/esbuild-plugin-babel-cjs","tags":["javascript","babel","esbuild","esbuild-plugin","commonjs"],"install":[{"cmd":"npm install esbuild-plugin-babel-cjs","lang":"bash","label":"npm"},{"cmd":"yarn add esbuild-plugin-babel-cjs","lang":"bash","label":"yarn"},{"cmd":"pnpm add esbuild-plugin-babel-cjs","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency - required to run any Babel transformations.","package":"@babel/core","optional":true}],"imports":[{"note":"Package uses CommonJS default export; require directly returns the plugin function.","wrong":"const babel = require('esbuild-plugin-babel-cjs').default;","symbol":"plugin (default)","correct":"const babel = require('esbuild-plugin-babel-cjs');"},{"note":"Default import works because the module has a default export that resolves to the plugin function.","wrong":"import { babel } from 'esbuild-plugin-babel-cjs';","symbol":"plugin (ESM)","correct":"import babel from 'esbuild-plugin-babel-cjs';"},{"note":"Type imports are available for config interface. Named type import is correct.","wrong":"import { BabelPluginConfig } from 'esbuild-plugin-babel-cjs';","symbol":"TypeScript types","correct":"import type { BabelPluginConfig } from 'esbuild-plugin-babel-cjs';"}],"quickstart":{"code":"const esbuild = require('esbuild');\nconst babel = require('esbuild-plugin-babel-cjs');\n\nesbuild.build({\n  entryPoints: ['index.js'],\n  bundle: true,\n  outfile: 'main.js',\n  plugins: [babel()],\n}).catch(() => process.exit(1));","lang":"javascript","description":"Minimal esbuild config that applies Babel transformations via the plugin. Ensure @babel/core is installed and Babel configuration is set separately."},"warnings":[{"fix":"Create a babel.config.json or pass config object to babel({ config: { presets: [...], plugins: [...] } }).","message":"Plugin 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Add target: ['es5'] to esbuild.build options.","message":"If targeting es5, esbuild must also have target: ['es5'] set; otherwise esbuild will output modern syntax first and Babel may not produce valid es5.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Replace require('esbuild-plugin-babel') with require('esbuild-plugin-babel-cjs').","message":"The 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.","severity":"deprecated","affected_versions":"==1.0.0"},{"fix":"Consider using esbuild's own transforms when possible for performance.","message":"Plugin uses a synchronous transform under the hood; large files or complex Babel presets may cause performance issues or blocking in esbuild's async pipeline.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Pass babel({ namespace: 'babel' }) to avoid conflicts.","message":"The plugin namespace option defaults to an empty string, which may conflict with other plugins. Use a specific namespace like 'babel' to isolate.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run 'npm install @babel/core --save-dev' or add it to devDependencies.","cause":"@babel/core is not installed or is missing from node_modules.","error":"Error: Cannot find module '@babel/core'"},{"fix":"Use default import: import babel from 'esbuild-plugin-babel-cjs' or require('esbuild-plugin-babel-cjs').","cause":"Attempting to import a non-existent named export (e.g., import { babel } from 'esbuild-plugin-babel-cjs').","error":"Error: Callback must be a function. Received undefined"},{"fix":"Create a babel.config.json in the project root or pass config option to babel().","cause":"No babel.config.json, .babelrc, or inline config provided.","error":"Error: No Babel configuration found"},{"fix":"Use import syntax: import babel from 'esbuild-plugin-babel-cjs';","cause":"Using require() in an ESM context (e.g., 'type':'module' in package.json).","error":"ReferenceError: require is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}