{"id":19149,"library":"babel-plugin-remove-unused-vars","title":"babel-plugin-remove-unused-vars","description":"A Babel plugin that automatically removes unused variables, imports, function arguments, and destructured bindings from JavaScript code, acting as a Babel-based autofix for ESLint's no-unused-vars rule. As of version 2.2.0, it supports source-to-source transformations and is intended for use as a build tool to clean up code. The plugin runs via Babel CLI or programmatically and handles common cases but has known limitations with deep assignment expressions. It is released under the MIT license with moderate maintenance cadence on GitHub, positioned as a more aggressive alternative to manual lint fixes or tree-shaking.","status":"active","version":"2.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/steelbrain/babel-plugin-remove-unused-vars","tags":["javascript","babel","eslint","fix","unused","variables"],"install":[{"cmd":"npm install babel-plugin-remove-unused-vars","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-remove-unused-vars","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-remove-unused-vars","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Runtime dependency for Babel plugin execution","package":"@babel/core","optional":false}],"imports":[{"note":"Plugin is CommonJS only; use require() in .babelrc or babel.config.js","wrong":"import plugin from 'babel-plugin-remove-unused-vars'","symbol":"default","correct":"module.exports = require('babel-plugin-remove-unused-vars')"},{"note":"No named exports; use default require","wrong":"import { PluginObj } from 'babel-plugin-remove-unused-vars'","symbol":"PluginObj","correct":"const plugin = require('babel-plugin-remove-unused-vars')"},{"note":"When using programmatically, pass the plugin function reference, not a string","wrong":"babel.transformSync(code, { plugins: ['babel-plugin-remove-unused-vars'] })","symbol":"programmatic usage","correct":"const babel = require('@babel/core'); const plugin = require('babel-plugin-remove-unused-vars'); babel.transformSync(code, { plugins: [plugin] })"}],"quickstart":{"code":"// Install: npm install --save-dev babel-plugin-remove-unused-vars\n// .babelrc\n{\n  \"plugins\": [\"babel-plugin-remove-unused-vars\"]\n}\n\n// Or via CLI:\n// npx babel --no-babelrc --retain-lines --plugins babel-plugin-remove-unused-vars --out-dir dist/ src/\n\n// Input: src/index.js\nimport { unused } from './utils';\nconst a = 1;\nconst b = a;\nconsole.log(b);\n\n// Output: dist/index.js\nimport {} from './utils';\nconst b = 1;\nconsole.log(b);","lang":"javascript","description":"Shows installation, configuration, CLI usage, and a simple transformation that removes unused imports and variables."},"warnings":[{"fix":"Run locally, inspect output with 'git diff', revert false removals manually.","message":"Plugin may produce false positives (removing actually used variables) or false negatives (keeping unused variables). Always review git diff after transformation.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Avoid deep assignments, or manually adjust after transformation.","message":"Deep assignment expressions (e.g., const a = foo(b = something())) are not fully handled. The right side may be removed even if the left side is used.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Run before other transformations like minification.","message":"Plugin is intended for source-to-source transformation, not for minification or bundling. It should be run early in the build pipeline.","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 --save-dev babel-plugin-remove-unused-vars' and ensure working directory has node_modules.","cause":"Plugin not installed or not in node_modules.","error":"Error: Cannot find module 'babel-plugin-remove-unused-vars'"},{"fix":"Use: babel.transformSync(code, { plugins: [require('babel-plugin-remove-unused-vars')] })","cause":"Using a string plugin name instead of the plugin function reference when calling Babel programmatically.","error":"TypeError: babel.transformSync is not a function"},{"fix":"Add presets explicitly: npx babel --no-babelrc --presets @babel/preset-env --plugins babel-plugin-remove-unused-vars","cause":"Missing @babel/preset-env or other presets; --no-babelrc disables .babelrc but the plugin alone doesn't parse modern syntax.","error":"Unexpected token (1:0) when running Babel with --no-babelrc"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}