{"id":19148,"library":"babel-plugin-remove-import-export","title":"babel-plugin-remove-import-export","description":"A Babel plugin that strips import and export declarations from source files, useful for preparing code snippets for platforms like LeetCode. Current stable version is 1.1.1 (last updated 2020). It is lightweight and simple, with no dependencies. Options allow selective removal of imports, exports, or default exports, and control over preserving named export declarations. Unlike general code cleanup tools, it specifically targets module syntax only.","status":"maintenance","version":"1.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/timwangdev/babel-plugin-remove-import-export","tags":["javascript","babel","plugin","transform","import","export","remove","strip"],"install":[{"cmd":"npm install babel-plugin-remove-import-export","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-remove-import-export","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-remove-import-export","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Use the short name in babel config; the full package name is only needed for installation.","wrong":"require('babel-plugin-remove-import-export')","symbol":"default plugin","correct":"plugins: ['remove-import-export']"},{"note":"Options must be in a nested array; otherwise they apply globally.","wrong":"plugins: ['remove-import-export', { removeImport: false }]","symbol":"plugin with options","correct":"plugins: [['remove-import-export', { removeImport: false }]]"},{"note":"The plugin is not a direct transform function; it must be passed to Babel's transform.","wrong":"require('babel-plugin-remove-import-export')(code)","symbol":"via Node API","correct":"require('@babel/core').transform(code, { plugins: ['remove-import-export'] })"}],"quickstart":{"code":"// Install: npm install --save-dev babel-plugin-remove-import-export\n// .babelrc\n{\n  \"plugins\": [\"remove-import-export\"]\n}\n// Input\nimport { LinkedList } from 'some-lib';\nfunction foo() { return new LinkedList(['bar']); }\nexport class Solution { add(a,b) { return a+b; } }\nexport default foo;\n// Output\nfunction foo() { return new LinkedList(['bar']); }\nclass Solution { add(a,b) { return a+b; } }","lang":"typescript","description":"Demonstrates basic usage: removing import/export declarations from a source file, preserving only the body."},"warnings":[{"fix":"Use option name exactly as spelled: 'preseveNamedDeclaration' (not 'preserveNamedDeclaration').","message":"Preserving named export declaration with preseveNamedDeclaration (sic) misspelled option. The correct option is 'preseveNamedDeclaration' (typo preserved for compatibility).","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Manually ensure removed imports are not used in the remaining code, or use a bundler/linter to detect dangling references.","message":"Removing imports may cause runtime errors if the code depends on those imports. The plugin does not check for usage.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Set 'removeExportDefault' to false in options to preserve default export.","message":"Default options remove all imports and exports (including default exports) unless overridden. Some users expect default exports to be preserved.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Avoid using with re-export statements, or test output manually.","message":"The plugin does not handle re-exports (e.g., export { x } from 'module') correctly; it may leave partial code.","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":"Run: npm install --save-dev babel-plugin-remove-import-export. Ensure .babelrc uses 'remove-import-export' (not the full name).","cause":"Plugin not installed or babel config refers to wrong name.","error":"Error: Cannot find module 'babel-plugin-remove-import-export'"},{"fix":"In .babelrc, use: \"plugins\": [[\"remove-import-export\", { \"removeImport\": false }]]","cause":"Options passed in wrong format (array spread instead of nested array).","error":"TypeError: Cannot read property 'removeImport' of undefined"},{"fix":"Verify option spelling; e.g., 'preseveNamedDeclaration' not 'preserveNamedDeclaration'. Also check .babelrc correct syntax.","cause":"Options not recognized (typo in option name) or plugin not applied correctly.","error":"The plugin generated some unexpected output (import/export still present)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}