{"id":19060,"library":"babel-plugin-filter-imports","title":"babel-plugin-filter-imports","description":"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.","status":"active","version":"4.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/ember-cli/babel-plugin-filter-imports","tags":["javascript","babel","babel-plugin"],"install":[{"cmd":"npm install babel-plugin-filter-imports","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-filter-imports","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-filter-imports","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This plugin operates on ESM import statements; it does not affect CommonJS require() calls.","wrong":"const warn = require('debugging-tools').warn;","symbol":"String (import name)","correct":"import { warn } from 'debugging-tools';"},{"note":"Use 'default' in the plugin config to remove the default import.","wrong":"import { default } from 'debugging-tools';","symbol":"default import","correct":"import log from 'debugging-tools';"},{"note":"Use '*' in the plugin config to remove a namespace import (star import).","wrong":"import { * } from 'debugging-tools';","symbol":"namespace import","correct":"import * as utils from 'debugging-tools';"},{"note":"Breaking change in v1.x: options must be nested under imports key. Old direct format no longer works.","wrong":"[\"filter-imports\", { \"debugging-tools\": [\"warn\"] }]","symbol":"plugin configuration","correct":"[\"filter-imports\", { imports: { \"debugging-tools\": [\"warn\"] } }]"}],"quickstart":{"code":"// Install plugin\n// npm install --save-dev babel-plugin-filter-imports\n\n// .babelrc or babel.config.js\n{\n  \"plugins\": [\n    [\"filter-imports\", {\n      \"imports\": {\n        \"debugging-tools\": [\"warn\", \"log\"],\n        \"another-module\": [\"default\"]\n      },\n      \"keepImports\": false\n    }]\n  ]\n}\n\n// Input source code\nimport { warn, log } from 'debugging-tools';\nimport defaultFunc from 'another-module';\n\nfunction example() {\n  warn('warning');\n  log('info');\n  defaultFunc();\n}\n\n// Transformed output (keepImports: false)\nfunction example() {\n  ;\n  ;\n  ;\n}\n\n// With keepImports: true, import statements remain but references are removed\nfunction example() {\n  ;\n  ;\n  ;\n}","lang":"javascript","description":"Demonstrates configuration with multiple imports, keepImports option, and resulting code transformation."},"warnings":[{"fix":"Wrap your import specifiers into { imports: { ... } } as shown in the README.","message":"Configuration object changed in v1.x: imports must be nested under 'imports' key.","severity":"breaking","affected_versions":"<1.0"},{"fix":"Upgrade to Babel 7, or use the babel6 branch for legacy support.","message":"v2.x removed support for Babel 6. Only Babel 7 is supported.","severity":"breaking","affected_versions":">=2.0"},{"fix":"Set keepImports: false in options if you want the import statements removed.","message":"Plugin only removes references, not import declarations by default. Use keepImports: false to also remove import statements.","severity":"gotcha","affected_versions":">=1.0"},{"fix":"Use ESM imports or pre-process with Babel to convert require to imports.","message":"The plugin does not handle CommonJS require() calls; only ESM import/export syntax is transformed.","severity":"gotcha","affected_versions":">=1.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-filter-imports'","cause":"Plugin not installed or not in node_modules.","error":"Error: [BABEL] unknown: Cannot find module 'babel-plugin-filter-imports'"},{"fix":"Change the plugin config to: ['filter-imports', { imports: { 'module': ['import'] } }]","cause":"Using the old flat configuration format without imports wrapper.","error":"Error: Plugin configuration must be an object with an 'imports' key (since v1.x)"},{"fix":"Ensure options.imports['module'] includes '*' to remove namespace imports.","cause":"Namespace import '*' not properly configured in imports object.","error":"TypeError: Cannot read property 'filter' of undefined (when using namespace import)"},{"fix":"Set keepImports: false to remove import declarations as well.","cause":"Default keepImports is true, so import declarations remain even if references are removed.","error":"Input source code still contains removed imports (keepImports default behavior)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}