Registry / devops / babel-plugin-filter-imports

babel-plugin-filter-imports

JSON →
library4.0.0jsnpmunverified

A Babel 7 plugin that removes references to specified imports in JavaScript modules, useful for stripping debugging code from production builds when combined with dead code elimination (e.g., UglifyJS). Version 4.0.0 supports Node >=8, with legacy branches for Babel 6 and 5. Key differentiators: configurable per-module import removal, optional retention of import declarations via keepImports option, and compatibility with default/namespace imports. Released under the ember-cli organization, actively maintained with SemVer.

npm install babel-plugin-filter-imports
INSTALL
IMPORT
SIG · BABEL-PLUGIN-FILTE
B
babel-plugin-filter-imports
devopsjavascriptv4.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.

String (import name)
import { warn } from 'debugging-tools';
const warn = require('debugging-tools').warn;
This plugin operates on ESM import statements; it does not affect CommonJS require() calls.
default import
import log from 'debugging-tools';
import { default } from 'debugging-tools';
Use 'default' in the plugin config to remove the default import.
namespace import
import * as utils from 'debugging-tools';
import { * } from 'debugging-tools';
Use '*' in the plugin config to remove a namespace import (star import).
plugin configuration
["filter-imports", { imports: { "debugging-tools": ["warn"] } }]
["filter-imports", { "debugging-tools": ["warn"] }]
Breaking change in v1.x: options must be nested under imports key. Old direct format no longer works.

Demonstrates configuration with multiple imports, keepImports option, and resulting code transformation.

// Install plugin // npm install --save-dev babel-plugin-filter-imports // .babelrc or babel.config.js { "plugins": [ ["filter-imports", { "imports": { "debugging-tools": ["warn", "log"], "another-module": ["default"] }, "keepImports": false }] ] } // Input source code import { warn, log } from 'debugging-tools'; import defaultFunc from 'another-module'; function example() { warn('warning'); log('info'); defaultFunc(); } // Transformed output (keepImports: false) function example() { ; ; ; } // With keepImports: true, import statements remain but references are removed function example() { ; ; ; }
Debug
Known issues
breakingConfiguration object changed in v1.x: imports must be nested under 'imports' key.
fix
Wrap your import specifiers into { imports: { ... } } as shown in the README.
affects: <1.0
breakingv2.x removed support for Babel 6. Only Babel 7 is supported.
fix
Upgrade to Babel 7, or use the babel6 branch for legacy support.
affects: >=2.0
gotchaPlugin only removes references, not import declarations by default. Use keepImports: false to also remove import statements.
fix
Set keepImports: false in options if you want the import statements removed.
affects: >=1.0
gotchaThe plugin does not handle CommonJS require() calls; only ESM import/export syntax is transformed.
fix
Use ESM imports or pre-process with Babel to convert require to imports.
affects: >=1.0
Errors
Common errors & fixes
Error: [BABEL] unknown: Cannot find module 'babel-plugin-filter-imports'
Plugin not installed or not in node_modules.
fix
Run 'npm install --save-dev babel-plugin-filter-imports'
Error: Plugin configuration must be an object with an 'imports' key (since v1.x)
Using the old flat configuration format without imports wrapper.
fix
Change the plugin config to: ['filter-imports', { imports: { 'module': ['import'] } }]
TypeError: Cannot read property 'filter' of undefined (when using namespace import)
Namespace import '*' not properly configured in imports object.
fix
Ensure options.imports['module'] includes '*' to remove namespace imports.
Input source code still contains removed imports (keepImports default behavior)
Default keepImports is true, so import declarations remain even if references are removed.
fix
Set keepImports: false to remove import declarations as well.
Upgrade
Version history
4.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Amazon
1
Resources
babel-plugin-filter-imports — npm install babel-plugin-filter-imports · libregistry