Registry / testing / babel-plugin-export-toplevel

babel-plugin-export-toplevel

JSON →
library1.0.0jsnpmunverified

A Babel plugin that automatically exports all top-level declarations (e.g., const, function, class) from a module. At version 1.0.0, it is a stable, single-purpose utility primarily used in testing to expose internal functions or variables for unit tests without modifying production exports. It only affects development builds and has no runtime dependencies. Unlike other export injection plugins, it specifically targets top-level names and preserves existing exports.

npm install babel-plugin-export-toplevel
INSTALL
IMPORT
SIG · BABEL-PLUGIN-EXPOR
B
babel-plugin-export-toplevel
testingjavascriptv1.0.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
module.exports = { plugins: ['export-toplevel'] }
import plugin from 'babel-plugin-export-toplevel'
Used as a Babel plugin reference in .babelrc or babel.config.js, not imported directly.
default
{ "plugins": ["export-toplevel"] }
{ "plugins": ["babel-plugin-export-toplevel"] }
In .babelrc, use the short name 'export-toplevel' without the babel-plugin- prefix (Babel resolves it automatically).
module.exports
const { exportToplevel } = require('babel-plugin-export-toplevel')
If using programmatic API, assign the plugin directly; no named export exists.

Install the plugin, configure in .babelrc, and see automatic export of top-level names for testing.

// Install: npm i --save-dev babel-plugin-export-toplevel // .babelrc { "plugins": ["export-toplevel"] } // Example input: src/example.js const hiddenFunction = () => {}; const publicFunction = () => {}; export default publicFunction; // Output: automatically adds exports for hiddenFunction // Equivalent to: export default publicFunction; export { hiddenFunction, publicFunction };
Debug
Known issues
gotchaPlugin only works in Babel 6/7; ensure Babel version compatibility.
fix
Use Babel 6 or 7.
affects: >=1.0.0
gotchaTop-level names that are already exported (either individually or via export {}) are not duplicated.
fix
No action needed; plugin skips already-exported names.
affects: >=1.0.0
gotchaDoes not export names from import statements (e.g., import { foo } from 'bar'; foo is not exported).
fix
Manually re-export imported names if needed.
affects: >=1.0.0
Errors
Common errors & fixes
SyntaxError: .../node_modules/babel-plugin-export-toplevel/lib/index.js: Unexpected token
The plugin is configured without Babel (e.g., using Node require) instead of being used as a Babel plugin.
fix
Use the plugin in Babel's .babelrc or babel.config.js, not via direct require in runtime code.
Babel configuration error: .babelrc contains unknown plugin: babel-plugin-export-toplevel
Plugin not installed in node_modules.
fix
Run 'npm install --save-dev babel-plugin-export-toplevel'.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
20 hits · last 30 days
node
18
OpenAI (training)
1
Resources
babel-plugin-export-toplevel — npm install babel-plugin-export-toplevel · libregistry