Registry / devops / babel-plugin-remove-import-export

babel-plugin-remove-import-export

JSON →
library1.1.1jsnpmunverified

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.

npm install babel-plugin-remove-import-export
INSTALL
IMPORT
SIG · BABEL-PLUGIN-REMOV
B
babel-plugin-remove-import-export
devopsjavascriptv1.1.1
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.

default plugin
plugins: ['remove-import-export']
require('babel-plugin-remove-import-export')
Use the short name in babel config; the full package name is only needed for installation.
plugin with options
plugins: [['remove-import-export', { removeImport: false }]]
plugins: ['remove-import-export', { removeImport: false }]
Options must be in a nested array; otherwise they apply globally.
via Node API
require('@babel/core').transform(code, { plugins: ['remove-import-export'] })
require('babel-plugin-remove-import-export')(code)
The plugin is not a direct transform function; it must be passed to Babel's transform.

Demonstrates basic usage: removing import/export declarations from a source file, preserving only the body.

// Install: npm install --save-dev babel-plugin-remove-import-export // .babelrc { "plugins": ["remove-import-export"] } // Input import { LinkedList } from 'some-lib'; function foo() { return new LinkedList(['bar']); } export class Solution { add(a,b) { return a+b; } } export default foo; // Output function foo() { return new LinkedList(['bar']); } class Solution { add(a,b) { return a+b; } }
Debug
Known issues
gotchaPreserving named export declaration with preseveNamedDeclaration (sic) misspelled option. The correct option is 'preseveNamedDeclaration' (typo preserved for compatibility).
fix
Use option name exactly as spelled: 'preseveNamedDeclaration' (not 'preserveNamedDeclaration').
affects: >=1.0.0
gotchaRemoving imports may cause runtime errors if the code depends on those imports. The plugin does not check for usage.
fix
Manually ensure removed imports are not used in the remaining code, or use a bundler/linter to detect dangling references.
affects: >=1.0.0
breakingDefault options remove all imports and exports (including default exports) unless overridden. Some users expect default exports to be preserved.
fix
Set 'removeExportDefault' to false in options to preserve default export.
affects: >=1.0.0
gotchaThe plugin does not handle re-exports (e.g., export { x } from 'module') correctly; it may leave partial code.
fix
Avoid using with re-export statements, or test output manually.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'babel-plugin-remove-import-export'
Plugin not installed or babel config refers to wrong name.
fix
Run: npm install --save-dev babel-plugin-remove-import-export. Ensure .babelrc uses 'remove-import-export' (not the full name).
TypeError: Cannot read property 'removeImport' of undefined
Options passed in wrong format (array spread instead of nested array).
fix
In .babelrc, use: "plugins": [["remove-import-export", { "removeImport": false }]]
The plugin generated some unexpected output (import/export still present)
Options not recognized (typo in option name) or plugin not applied correctly.
fix
Verify option spelling; e.g., 'preseveNamedDeclaration' not 'preserveNamedDeclaration'. Also check .babelrc correct syntax.
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
babel-plugin-remove-import-export — npm install babel-plugin-remove-import-export · libregistry