Prettier Plugin: Organize Imports

4.3.0 · active · verified Sun Apr 19

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.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates installing the plugin and configuring Prettier v3 to automatically organize imports in a TypeScript project upon formatting.

{
  "name": "my-project",
  "version": "1.0.0",
  "devDependencies": {
    "prettier": "^3.0.0",
    "typescript": "^5.0.0",
    "prettier-plugin-organize-imports": "^4.0.0"
  }
}

// .prettierrc.json
{
  "plugins": [
    "prettier-plugin-organize-imports"
  ]
}

// src/main.ts (before formatting)
import { z } from "./utils";
import type { Bar } from './types';
import { foo } from "./helpers";


const myVar: Bar = foo + z;

console.log(myVar);

// Terminal command to format:
// npx prettier --write "src/**/*.ts"

view raw JSON →