Registry / devops / babel-plugin-transform-require-default

babel-plugin-transform-require-default

JSON →
library0.1.7jsnpmunverified

A Babel plugin (v0.1.7, last updated 2018) that automatically transforms CommonJS require() calls to access .default for ES modules that use __esModule. Addresses Babel 6/7's breaking change where exported defaults are no longer assigned to module.exports, requiring manual .default access. Helps maintain backward compatibility in mixed ES module / CommonJS codebases. Use with caution: modifies module resolution behavior and may cause unintended side effects. Consider alternatives like using ES import syntax or newer Babel interop settings.

npm install babel-plugin-transform-require-default
INSTALL
IMPORT
SIG · BABEL-PLUGIN-TRANS
B
babel-plugin-transform-require-default
devopsjavascriptv0.1.7
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
module.exports = { plugins: [['transform-require-default', { exclude: /lodash/ }]] }
require('babel-plugin-transform-require-default').default
The plugin exports a function, not an object. It does not have a default export; it's a CommonJS module.

Configures the Babel plugin to transform require() calls, excluding certain modules, and shows the result of the transformation.

// .babelrc or babel.config.js module.exports = { plugins: [ ['transform-require-default', { exclude: ['lodash', /^react/] }] ] }; // Before: const a = require('a'); // After: function __require_default_func__(module) { return module && module.__esModule ? module["default"] : module; } const a = __require_default_func__(require('a'));
Debug
Known issues
breakingPlugin modifies all require() calls to add default interop, which may break modules that don't export defaults or that rely on the raw module object.
fix
Use exclude option to skip modules that don't need default interop (e.g., lodash, React).
affects: >=0.0.0
breakingPlugin uses __esModule heuristic; modules that don't set __esModule but have a default export will still be transformed, causing 'default.default' access.
fix
Ensure all affected modules set __esModule, or use exclude to skip them.
affects: >=0.0.0
gotchaPlugin does not handle dynamic require() with variables or computed expressions.
fix
Use static require() calls if you need transformation.
affects: >=0.0.0
gotchaPlugin may interfere with other Babel plugins that also transform require (e.g., babel-plugin-import).
fix
Test carefully with your plugin stack, and adjust plugin ordering.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: require(...).default is not a function
Module exports a function directly, not as default export. Plugin incorrectly adds .default.
fix
Add the module to the exclude list: exclude: ["my-module"]
Module "lodash" has no default export
Plugin transforms require('lodash') to require('lodash').default, but lodash doesn't have __esModule.
fix
Use exclude: ['lodash'] or set strict mode.
Upgrade
Version history
0.1.7latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
babel-plugin-transform-require-default — npm install babel-plugin-transform-require-default · libregistry