{"id":19054,"library":"babel-plugin-export-toplevel","title":"babel-plugin-export-toplevel","description":"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.","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/MaienM/babel-plugin-export-toplevel","tags":["javascript","babel"],"install":[{"cmd":"npm install babel-plugin-export-toplevel","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-export-toplevel","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-export-toplevel","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Used as a Babel plugin reference in .babelrc or babel.config.js, not imported directly.","wrong":"import plugin from 'babel-plugin-export-toplevel'","symbol":"plugin","correct":"module.exports = { plugins: ['export-toplevel'] }"},{"note":"In .babelrc, use the short name 'export-toplevel' without the babel-plugin- prefix (Babel resolves it automatically).","wrong":"{\n  \"plugins\": [\"babel-plugin-export-toplevel\"]\n}","symbol":"default","correct":"{\n  \"plugins\": [\"export-toplevel\"]\n}"},{"note":"If using programmatic API, assign the plugin directly; no named export exists.","wrong":"const { exportToplevel } = require('babel-plugin-export-toplevel')","symbol":"module.exports"}],"quickstart":{"code":"// Install: npm i --save-dev babel-plugin-export-toplevel\n// .babelrc\n{\n  \"plugins\": [\"export-toplevel\"]\n}\n\n// Example input: src/example.js\nconst hiddenFunction = () => {};\nconst publicFunction = () => {};\nexport default publicFunction;\n\n// Output: automatically adds exports for hiddenFunction\n// Equivalent to:\nexport default publicFunction;\nexport { hiddenFunction, publicFunction };","lang":"javascript","description":"Install the plugin, configure in .babelrc, and see automatic export of top-level names for testing."},"warnings":[{"fix":"Use Babel 6 or 7.","message":"Plugin only works in Babel 6/7; ensure Babel version compatibility.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"No action needed; plugin skips already-exported names.","message":"Top-level names that are already exported (either individually or via export {}) are not duplicated.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Manually re-export imported names if needed.","message":"Does not export names from import statements (e.g., import { foo } from 'bar'; foo is not exported).","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use the plugin in Babel's .babelrc or babel.config.js, not via direct require in runtime code.","cause":"The plugin is configured without Babel (e.g., using Node require) instead of being used as a Babel plugin.","error":"SyntaxError: .../node_modules/babel-plugin-export-toplevel/lib/index.js: Unexpected token"},{"fix":"Run 'npm install --save-dev babel-plugin-export-toplevel'.","cause":"Plugin not installed in node_modules.","error":"Babel configuration error: .babelrc contains unknown plugin: babel-plugin-export-toplevel"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}