This Prettier plugin automates the organization of import statements within your JavaScript, TypeScript, JSX, TSX, and Vue files. It leverages the TypeScript language service API's `organizeImports` feature, which is the same logic used by VS Code's 'Organize Imports' action. The plugin sorts, combines, and removes unused imports, ensuring consistent import structures across your codebase and reducing merge conflicts related to import ordering. The current stable version is 4.3.0, with minor releases occurring periodically to address bug fixes, improve compatibility with `vue-tsc`, and introduce new configuration options like `organizeImportsTypeOrder`. A key differentiator is its reliance on the robust TypeScript language service for import logic, offering zero-config setup for Prettier v2 users and minimal configuration for Prettier v3. It acts by extending and overriding Prettier's built-in parsers, meaning it's incompatible with other plugins that attempt to do the same for `babel`, `typescript`, or `vue` parsers. It primarily manages peer dependencies `prettier`, `typescript`, and optionally `vue-tsc` for Vue.js support.
npm install prettier-plugin-organize-importsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates installing the plugin and configuring Prettier v3 to automatically organize imports in a TypeScript project upon formatting.
Update your Prettier configuration file (e.g., `.prettierrc.json`) to include `{"plugins": ["prettier-plugin-organize-imports"]}`.Remove `@volar/vue-typescript` and `@volar/vue-language-plugin-pug` from your dependencies and install `vue-tsc` and `@vue/language-plugin-pug` instead. Update your `vueCompilerOptions` if using Pug.
Upgrade `vue-tsc` simultaneously with `prettier-plugin-organize-imports` to meet the peer dependency requirements (e.g., `npm i -D prettier-plugin-organize-imports vue-tsc@^3.0.0`).
Ensure `prettier-plugin-organize-imports` is the only plugin overriding these specific parsers in your Prettier configuration. Adjust plugin order if necessary, understanding that the last one loaded wins.
Add or update the `jsx` compiler option in your `tsconfig.json` to `"react"`.
Consult Prettier's documentation on 'Integrating with Linters' and disable conflicting import-related rules in your linter configuration.
Add `prettier-plugin-organize-imports` to the `plugins` array in your Prettier configuration file (e.g., `.prettierrc.json`).
Ensure you are using `prettier-plugin-organize-imports` v3.1.1 or later, and that your `@volar/vue-typescript` (or `vue-tsc` for v4+) peer dependency meets the specified version requirements.
Ensure `vue-tsc` is installed and meets the plugin's peer dependency requirements (v2.1.0 or v3.0.0+). If using Pug templates, install `@vue/language-plugin-pug` and configure it in `vueCompilerOptions`.
Upgrade to `prettier-plugin-organize-imports` v3.2.2 or higher, which includes a fix for the performance regression.