{"id":19036,"library":"babel-plugin-danger-remove-unused-import","title":"babel-plugin-danger-remove-unused-import","description":"Babel plugin to remove unused imports, reducing bundle size. Version 2.0.0 as of latest release. Updated sporadically; last commit 2020. Key differentiator: aggressively removes imports even if side effects exist (hence 'dangerous'), with opt-out via ignore option. Alternatives (babel-plugin-transform-remove-imports) are less aggressive. Only supports ESM imports, not CommonJS require statements.","status":"deprecated","version":"2.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/imcuttle/babel-plugin-danger-remove-unused-import","tags":["javascript","imcuttle","shake","remove-unused","babel-plugin"],"install":[{"cmd":"npm install babel-plugin-danger-remove-unused-import","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-danger-remove-unused-import","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-danger-remove-unused-import","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"CJS module; no default export. Use require() or .default in ESM.","wrong":"import plugin from 'babel-plugin-danger-remove-unused-import'","symbol":"default","correct":"module.exports = require('babel-plugin-danger-remove-unused-import')"},{"note":"No named export; use default require.","wrong":"import { plugin } from 'babel-plugin-danger-remove-unused-import'","symbol":"plugin","correct":"const plugin = require('babel-plugin-danger-remove-unused-import')"},{"note":"Plugin name without prefix works if package is installed.","wrong":"plugins: ['babel-plugin-danger-remove-unused-import']","symbol":"Babel config","correct":"plugins: [['danger-remove-unused-import', { ignore: ['react'] }]]"}],"quickstart":{"code":"// babel.config.js\nmodule.exports = {\n  plugins: [\n    ['danger-remove-unused-import', { ignore: ['react'] }]\n  ]\n};\n\n// Input: import unused from 'unused-module';\n// Output: (import removed)\n\nconst plugin = require('babel-plugin-danger-remove-unused-import');\nconst babel = require('@babel/core');\nconst code = `import _ from 'lodash'; import React from 'react'; console.log('hi');`;\nbabel.transformSync(code, { plugins: [[plugin, { ignore: ['react'] }]] });\n// Result: import React from 'react'; console.log('hi');","lang":"javascript","description":"Show basic usage: configure plugin with ignore option to preserve React imports while removing unused lodash import."},"warnings":[{"fix":"Add known side-effect imports to ignore array: { ignore: ['polyfill', 'style.css'] }","message":"Plugin removes imports that may have side effects (e.g., import 'polyfill'). Use ignore option to preserve.","severity":"breaking","affected_versions":">0.0.0"},{"fix":"Consider alternatives like babel-plugin-transform-remove-imports or custom logic.","message":"Package not updated since 2020; no support for Babel 7.x modern features.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Use plugin only for static import removal; dynamic imports remain.","message":"Does not handle dynamic imports or require() statements; only static ESM imports.","severity":"gotcha","affected_versions":">0.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 babel-plugin-danger-remove-unused-import --save-dev` and ensure correct babel.config.js plugins entry.","cause":"Package not installed or placed in wrong plugins array path.","error":"Plugin threw: Cannot find module 'babel-plugin-danger-remove-unused-import'"},{"fix":"Use @babel/preset-env and ensure Babel version 6 or 7 compatibility in plugin's peerDependencies.","cause":"Plugin not compatible with Babel 7.x parser or used without proper preset/env.","error":"TypeError: Cannot read property 'references' of undefined"},{"fix":"Use TypeScript compiler or type-aware plugin for type-only imports.","cause":"Plugin only checks runtime references, not TypeScript type usage.","error":"The plugin does not remove imports that are used as type annotations"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}