Registry / devops / babel-plugin-danger-remove-unused-import

babel-plugin-danger-remove-unused-import

JSON →
library2.0.0jsnpmunverified

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.

npm install babel-plugin-danger-remove-unused-import
INSTALL
IMPORT
SIG · BABEL-PLUGIN-DANGE
B
babel-plugin-danger-remove-unused-import
devopsjavascriptv2.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.

default
module.exports = require('babel-plugin-danger-remove-unused-import')
import plugin from 'babel-plugin-danger-remove-unused-import'
CJS module; no default export. Use require() or .default in ESM.
plugin
const plugin = require('babel-plugin-danger-remove-unused-import')
import { plugin } from 'babel-plugin-danger-remove-unused-import'
No named export; use default require.
Babel config
plugins: [['danger-remove-unused-import', { ignore: ['react'] }]]
plugins: ['babel-plugin-danger-remove-unused-import']
Plugin name without prefix works if package is installed.

Show basic usage: configure plugin with ignore option to preserve React imports while removing unused lodash import.

// babel.config.js module.exports = { plugins: [ ['danger-remove-unused-import', { ignore: ['react'] }] ] }; // Input: import unused from 'unused-module'; // Output: (import removed) const plugin = require('babel-plugin-danger-remove-unused-import'); const babel = require('@babel/core'); const code = `import _ from 'lodash'; import React from 'react'; console.log('hi');`; babel.transformSync(code, { plugins: [[plugin, { ignore: ['react'] }]] }); // Result: import React from 'react'; console.log('hi');
Debug
Known issues
breakingPlugin removes imports that may have side effects (e.g., import 'polyfill'). Use ignore option to preserve.
fix
Add known side-effect imports to ignore array: { ignore: ['polyfill', 'style.css'] }
affects: >0.0.0
deprecatedPackage not updated since 2020; no support for Babel 7.x modern features.
fix
Consider alternatives like babel-plugin-transform-remove-imports or custom logic.
affects: >=1.0.0
gotchaDoes not handle dynamic imports or require() statements; only static ESM imports.
fix
Use plugin only for static import removal; dynamic imports remain.
affects: >0.0.0
Errors
Common errors & fixes
Plugin threw: Cannot find module 'babel-plugin-danger-remove-unused-import'
Package not installed or placed in wrong plugins array path.
fix
Run `npm install babel-plugin-danger-remove-unused-import --save-dev` and ensure correct babel.config.js plugins entry.
TypeError: Cannot read property 'references' of undefined
Plugin not compatible with Babel 7.x parser or used without proper preset/env.
fix
Use @babel/preset-env and ensure Babel version 6 or 7 compatibility in plugin's peerDependencies.
The plugin does not remove imports that are used as type annotations
Plugin only checks runtime references, not TypeScript type usage.
fix
Use TypeScript compiler or type-aware plugin for type-only imports.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Resources
babel-plugin-danger-remove-unused-import — npm install babel-plugin-danger-remove-unused-import · libregistry