prettier-plugin-unused-imports-configurable
raw JSON → 1.15.0 verified Sat Apr 25 auth: no javascript
A Prettier plugin that automatically removes unused imports from JavaScript, TypeScript, and React files during formatting. Version 1.15.0 is the latest stable release, actively maintained with monthly updates. Key differentiators: configurable to ignore specific directories (ideal for monorepos), supports exclusion comments per file, handles namespace imports, aliases, and qualified usages, merges duplicate imports, and has extensive test coverage (>80%). Compared to similar plugins like `prettier-plugin-unused-imports`, this one offers more granular control over which folders to exclude.
Common errors
error Ignore directories option not working; imports in ignored folder are still removed ↓
cause The option name 'ignoredDirectories' is misspelled; correct is 'ignoreDirectories'.
fix
Use 'ignoreDirectories' (without 'd' in 'ignore') in .prettierrc.
error Import removal broken after upgrading to v1.15.0; TypeScript errors for some imports ↓
cause Parser changed from babel-ts to TypeScript, which may parse JSX or type-only imports differently.
fix
Upgrade prettier to ^3.4.2. If issues persist, downgrade to 1.14.0 or file an issue on GitHub.
error Exclusion comment not working; import still removed ↓
cause Comment must be exactly 'prettier-ignore-unused-imports-configurable' and placed before the first import declaration.
fix
Check the comment spelling and ensure it appears on its own line above the first import.
Warnings
breaking Version 1.15.0 replaced babel-ts parser with TypeScript parser for .ts/.tsx files. May cause differences in import detection for complex TypeScript features. ↓
fix Review your TypeScript imports after upgrading. The new parser may detect usage differently.
gotcha The option name is 'ignoreDirectories' (camelCase), not 'ignoredDirectories' or 'ignore-directories'. Incorrect casing will be silently ignored. ↓
fix Use 'ignoreDirectories' exactly as documented in .prettierrc.
gotcha Exclusion comment must be exactly '// prettier-ignore-unused-imports-configurable' and placed before the first import declaration. Comments after the first import are ignored. ↓
fix Place the comment on its own line above the first import statement in the file.
deprecated Version 1.15.0 deprecated the babel-ts parser; the new TypeScript parser may require Prettier >=3.4.2. ↓
fix Ensure you have Prettier ^3.4.2 installed. If you encounter parsing errors, downgrade to <1.15.0.
Install
npm install prettier-plugin-unused-imports-configurable yarn add prettier-plugin-unused-imports-configurable pnpm add prettier-plugin-unused-imports-configurable Imports
- Plugin wrong
import prettierPluginUnusedImports from 'prettier-plugin-unused-imports-configurable'correctNot directly imported; placed in .prettierrc: { "plugins": ["prettier-plugin-unused-imports-configurable"] } - ignoreDirectories wrong
Set via environment variable or as a separate optioncorrectAdd to .prettierrc: { "ignoreDirectories": ["src/generated"] } - Exclusion comment wrong
// prettier-ignore-unused-importscorrect// prettier-ignore-unused-imports-configurable (above the first import declaration)
Quickstart
npm install --save-dev prettier prettier-plugin-unused-imports-configurable
echo '{"plugins": ["prettier-plugin-unused-imports-configurable"], "ignoreDirectories": ["src/generated"]}' > .prettierrc
echo 'import { unusedVar } from "./module"' > src/test.ts
prettier --write src/test.ts
# src/test.ts now has: (empty file, unused import removed)