Registry / serialization / babel-plugin-transform-commonjs-es2015-modules

babel-plugin-transform-commonjs-es2015-modules

JSON →
library4.0.1jsnpmunverified

Babel plugin that transforms CommonJS require/exports syntax into ES2015 import/export statements. Version 4.0.1 is stable but not actively maintained; the package saw its last release in 2017. It supports most popular CommonJS patterns, including those generated by Babel's own CJS transform. Unlike similar tools (cjs-to-es6, lebab), it operates as a Babel plugin, making it easy to integrate into existing Babel pipelines. The transformation is lossy in some edge cases (e.g., dynamic requires or module.exports reassignment) and does not handle all CJS idioms.

npm install babel-plugin-transform-commonjs-es2015-modules
INSTALL
IMPORT
SIG · BABEL-PLUGIN-TRANS
B
babel-plugin-transform-commonjs-es2015-modules
serializationjavascriptv4.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

default
import plugin from 'babel-plugin-transform-commonjs-es2015-modules'
const plugin = require('babel-plugin-transform-commonjs-es2015-modules')
Babel plugins are typically used via string name in .babelrc, not imported directly. If importing programmatically, ESM import works as shown.
plugin as string
plugins: ['transform-commonjs-es2015-modules']
plugins: ['babel-plugin-transform-commonjs-es2015-modules']
Babel resolves plugin names without the prefix; using full 'babel-plugin-...' is also valid but more verbose.

Shows basic configuration and transformation of CommonJS require/exports to ES module imports/exports.

// .babelrc { "plugins": ["transform-commonjs-es2015-modules"] } // input.js (CJS) var foo = require('bar'); module.exports = foo; // Run: npx babel input.js --plugins transform-commonjs-es2015-modules // Output: import foo from 'bar'; export default foo;
Debug
Known issues
gotchaDoes not handle dynamic requires like `require('./' + name)`. The plugin will skip or incorrectly transform them.
fix
Manually refactor dynamic requires or use a different tool. Consider bundlers like Webpack that handle dynamic imports natively.
affects: <=4.0.1
deprecatedPackage has not been updated since 2017 and may not work with modern Babel versions (v7+). Babel 6 is still supported but Babel 7 changed plugin API.
fix
Use with Babel 6 or check if compatible with Babel 7 via shim. For newer projects, consider alternatives like lebab or manual conversion.
affects: >=4.0.0
gotcha`module.exports` reassignment to a non-identifier, e.g., `module.exports = function(){}`, is transformed to `export default function(){}` but this may break in some module systems (e.g., AMD).
fix
Review output for anonymous exports; consider using named function expressions.
affects: <=4.0.1
gotchaNested `require` calls inside functions are not hoisted to imports. For example, `function a() { var x = require('x'); }` stays as-is.
fix
Manually move requires to top level if ES module semantics are required.
affects: <=4.0.1
Errors
Common errors & fixes
Module 'babel-plugin-transform-commonjs-es2015-modules' is not found
Plugin not installed or Babel cannot resolve it.
fix
Run `npm install babel-plugin-transform-commonjs-es2015-modules`
Error: Plugin transform-commonjs-es2015-modules specified in .babelrc is not a valid plugin
Incorrect plugin name or typo.
fix
Use correct plugin name: 'transform-commonjs-es2015-modules' (without 'babel-plugin-' prefix).
TypeError: Property left of AssignmentExpression expected node to be of a type ["Identifier", "Pattern"] but got "MemberExpression"
Unsupported pattern like `module.exports.property = ...` with complex expressions.
fix
Simplify the assignment or refactor to avoid member expression on module.exports.
Upgrade
Version history
4.0.1latest on npm
Audit
Dependencies
@babel/coreoptionalRequires Babel core to run as a plugin; not a direct dependency but peer/runtime requirement.
Agent activity
18 hits · last 30 days
node
14
OpenAI (training)
2
Resources
babel-plugin-transform-commonjs-es2015-modules — npm install babel-plugin-transform-commonjs-es2015-modules · libregistry