prettier-plugin-astro-organize-imports
raw JSON → 0.4.12 verified Sat Apr 25 auth: no javascript
A Prettier plugin that organizes imports in Astro files by removing unused imports, coalescing duplicate imports, and sorting them using the TypeScript language service API's organizeImports feature. The current stable version is 0.4.12. It is actively maintained with frequent releases. Differentiators: specifically for Astro files, provides explicit compatibility with prettier-plugin-astro and prettier-plugin-tailwindcss through per-plugin workarounds, and supports configurable modes (All, SortAndCombine, RemoveUnused).
Common errors
error Error: @astrojs/compiler must be installed to use this plugin ↓
cause Missing dependency or peer dependency on prettier-plugin-astro which provides Astro compiler.
fix
Install prettier-plugin-astro: npm install -D prettier-plugin-astro
error Cannot find module 'prettier-plugin-astro-organize-imports' ↓
cause Plugin not installed or incorrect package name in .prettierrc.
fix
Install the plugin: npm install -D prettier-plugin-astro-organize-imports. Ensure spelling matches in .prettierrc.
error Error: Failed to load plugin 'prettier-plugin-astro-organize-imports' ↓
cause Incompatible Prettier version (< 3.0) or misconfiguration.
fix
Update Prettier to v3 or later: npm install -D prettier@^3
Warnings
gotcha Plugin must be last in the plugins array to ensure compatibility with prettier-plugin-astro and prettier-plugin-tailwindcss. ↓
fix List prettier-plugin-astro-organize-imports as the final entry in the plugins array in .prettierrc.
breaking In v0.4.12, TypeScript 6 organizeImports API change causes semicolons to be added to import statements. ↓
fix Ensure you use TypeScript >=6 or apply a workaround; see release notes.
gotcha Files containing '// organize-imports-ignore' or '// tslint:disable:ordered-imports' are skipped and not processed. ↓
fix Remove those comments from files you intend to format.
deprecated The astroOrganizeImportsInScriptTags option added in v0.4.9 may be deprecated in future versions. ↓
fix Use astroOrganizeImportsMode instead if available.
Install
npm install prettier-plugin-astro-organize-imports yarn add prettier-plugin-astro-organize-imports pnpm add prettier-plugin-astro-organize-imports Imports
- default wrong
Not a module to import in codecorrectNo import needed; declare in .prettierrc plugins array - prettier-plugin-astro-organize-imports wrong
Using require('prettier-plugin-astro-organize-imports') in code filecorrectIn .prettierrc: "plugins": ["prettier-plugin-astro", "prettier-plugin-tailwindcss", "prettier-plugin-astro-organize-imports"]
Quickstart
// .prettierrc
{
"plugins": [
"prettier-plugin-astro",
"prettier-plugin-tailwindcss",
"prettier-plugin-astro-organize-imports"
],
"overrides": [
{
"files": "*.astro",
"options": {
"parser": "astro"
}
}
],
"astroOrganizeImportsMode": "All"
}