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).

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
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.
npm install prettier-plugin-astro-organize-imports
yarn add prettier-plugin-astro-organize-imports
pnpm add prettier-plugin-astro-organize-imports

Configuration to enable the plugin for Astro files, with recommended order and mode set to All.

// .prettierrc
{
  "plugins": [
    "prettier-plugin-astro",
    "prettier-plugin-tailwindcss",
    "prettier-plugin-astro-organize-imports"
  ],
  "overrides": [
    {
      "files": "*.astro",
      "options": {
        "parser": "astro"
      }
    }
  ],
  "astroOrganizeImportsMode": "All"
}