Registry / babel-plugin-transform-export-default-name

babel-plugin-transform-export-default-name

JSON →
library2.1.0jsnpmunverified

Babel plugin that transforms export default of anonymous functions, arrow functions, and anonymous classes to named exports using the filename as the variable name. Version 2.1.0 is current. Released sporadically; last update was several years ago. Key differentiator: solves stack trace readability by assigning a derived name from the file (e.g., foo-bar.js becomes fooBar), improving debugging. Unlike other plugins that only handle function declarations, this targets anonymous/arrow function and class expressions. Works with Babel 6 and 7 (likely).

npm install babel-plugin-transform-export-default-name
INSTALL
IMPORT
SIG · BABEL-PLUGIN-TRANS
B
babel-plugin-transform-export-default-name
javascriptv2.1.0
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.

plugin (default)
module.exports = { plugins: ['transform-export-default-name'] }
module.exports = { plugins: ['babel-plugin-transform-export-default-name'] }
When using .babelrc, just use the short name without prefix
plugin (programmatic API)
require('babel-plugin-transform-export-default-name')
require('babel-plugin-transform-export-default-name').default
This is a traditional CJS module, no default export
ESM import
import plugin from 'babel-plugin-transform-export-default-name'
import { plugin } from 'babel-plugin-transform-export-default-name'
The package does not ship ESM; named import will fail

Shows how to enable the plugin and the transformation of an anonymous arrow function default export to a named variable.

// .babelrc { "plugins": ["transform-export-default-name"] } // foo.js // Input: export default () => {}; // Output: let foo = () => {}; export default foo;
Debug
Known issues
breakingPlugin may conflict with other Babel plugins that also transform export default (e.g., @babel/plugin-proposal-export-default-from). Order matters: run this plugin before others that re-export.
fix
Ensure this plugin is listed before any plugin that handles export-all or re-exporting.
affects: >=2.0.0
deprecatedPackage has not been updated in years; may not support Babel 7 clearify. It is not officially maintained.
fix
Consider using @babel/plugin-proposal-export-default-from or monkey-patch Babel transform output for named functions.
affects: >=2.0.0
gotchaUses lodash.camelCase; filenames with unusual characters may produce unexpected variable names (e.g., numbers, underscores).
fix
Check transformed output for valid identifiers; avoid file names starting with digits or containing special chars.
affects: >=1.0.0
gotchaOnly transforms anonymous functions and arrow functions; named exports or non-function/class default exports remain unchanged.
fix
Use only for anonymous default exports; for named exports, use other tools.
affects: >=1.0.0
gotchaDoes not transform export default of anonymous class if the class is named in the same file (e.g., export default class Foo {} -> stays as Foo). Only unnamed classes are affected.
fix
Ensure the default export is truly anonymous; otherwise, no transformation occurs.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'babel-plugin-transform-export-default-name'
Plugin not installed or missing from node_modules.
fix
npm install --save-dev babel-plugin-transform-export-default-name
Error: Plugin/Preset files are not allowed to export objects, only functions.
Using a very old Babel version that expects different plugin format (Babel 6 vs 7).
fix
Install @babel/core@^7.0.0 and ensure compatibility; consider alternative plugin.
TypeError: Cannot assign to read only property 'name' of function
Plugin incorrectly tries to assign name to a function that is already named; edge case with named default exports.
fix
Ensure the default export is anonymous; remove any explicit name declaration.
Unexpected token, expected "export" (e.g., after transformation, syntax error)
Plugin corrupts export due to misordered plugins or conflicting transforms.
fix
Ensure this plugin runs first in the plugin list before other export transforms.
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies
@babel/corerequiredpeerDependency required to function as a Babel plugin
Agent activity
4 hits · last 30 days
node
4
Resources