{"id":19056,"library":"babel-plugin-extract-export","title":"Extract Export Babel Plugin","description":"A Babel plugin that extracts a specific ESM export and its dependencies from a file, based on a fork of NextJS's SSG transform plugin. Current version 0.1.0, single release. It operates by performing static analysis with Babel to remove unused exports and import statements, outputting only the targeted export and its prerequisites. Differentiates from tree-shaking tools by allowing per-export extraction at build time, useful for code splitting or dynamic imports. Note: The package has not been updated since initial release and may have limited compatibility with newer Babel versions.","status":"maintenance","version":"0.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/souporserious/babel-plugin-extract-export","tags":["javascript"],"install":[{"cmd":"npm install babel-plugin-extract-export","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-extract-export","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-extract-export","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency required for transforming code","package":"@babel/core","optional":false},{"reason":"Required to parse TypeScript syntax when TS files are processed","package":"@babel/plugin-syntax-typescript","optional":true}],"imports":[{"note":"Plugin is CommonJS only; no ESM or TypeScript typings provided.","symbol":"default","correct":"const extractExport = require('babel-plugin-extract-export')"},{"note":"The plugin exports a single default function. As of v0.1.0, ESM syntax works only if your bundler interops with CJS.","wrong":"import * as extractExport from 'babel-plugin-extract-export'","symbol":"default","correct":"import extractExport from 'babel-plugin-extract-export'"},{"note":"When using Babel's plugins array, the plugin and its options are passed as a tuple inside an array, but some may mistakenly wrap it twice.","wrong":"plugins: [[extractExport, { exportName: 'MyExport' }]]","symbol":"default","correct":"plugins: [extractExport, { exportName: 'MyExport' }]"}],"quickstart":{"code":"const babel = require('@babel/core');\nconst syntaxTypeScript = require('@babel/plugin-syntax-typescript');\nconst extractExport = require('babel-plugin-extract-export');\n\nconst source = `\nimport { Image } from 'system';\nexport const Avatar = () => <Image />;\ntype BoxProps = { children: any };\nexport const Box = (props: BoxProps) => <div {...props} />;\n`;\n\nconst result = babel.transformSync(source, {\n  configFile: false,\n  plugins: [\n    [syntaxTypeScript, { isTSX: true }],\n    [extractExport, { exportName: 'Avatar' }],\n  ],\n});\n\nconsole.log(result.code);\n// Expected output:\n// import { Image } from 'system';\n// export const Avatar = () => <Image />;","lang":"javascript","description":"Shows how to use the plugin with Babel to extract a specific export (Avatar) and its dependencies from a source string."},"warnings":[{"fix":"Ensure Babel 7 compatibility; upgrade to future releases if available.","message":"Version 0.1.0 is the only release and may break with Babel versions other than 7.x. No tests for Babel 8.","severity":"breaking","affected_versions":">=0.1.0"},{"fix":"Consider using NextJS's SSG transform directly or a more maintained alternative like babel-plugin-transform-imports.","message":"The plugin is in maintenance mode with no recent updates. It may be deprecated or superseded by NextJS's official transforms.","severity":"deprecated","affected_versions":">=0.1.0"},{"fix":"Use separate passes or a different plugin if you need to extract multiple exports.","message":"Plugin only extracts a single named export (via 'exportName' option). Multiple exports or default exports are not supported.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Always include the syntax plugin with appropriate configuration for TSX files.","message":"Requires @babel/plugin-syntax-typescript with { isTSX: true } when extracting from TypeScript JSX files; otherwise parsing may fail silently.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run 'yarn add babel-plugin-extract-export' or 'npm install babel-plugin-extract-export'.","cause":"Package not installed or node_modules missing.","error":"Error: Cannot find module 'babel-plugin-extract-export'"},{"fix":"Use [[plugin, options]] syntax correctly: 'plugins: [[extractExport, { exportName: 'Avatar' }]]'.","cause":"Passing the plugin incorrectly to Babel's plugins array; likely double-wrapped in array.","error":"TypeError: plugin is not a function"},{"fix":"Ensure the file has an exported variable or function with the exact name given in exportName option.","cause":"Plugin encountered a file without any named exports matching the specified exportName, or the file is not parseable.","error":"Cannot read property 'replace' of undefined at ... PluginPass.ExportNamedDeclaration"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}