prettier-plugin-sorted
raw JSON → 2.0.0 verified Sat Apr 25 auth: no javascript
A zero-config Prettier plugin for sorting JavaScript and TypeScript imports. Version 2.0.0 requires Prettier ^2.0.0 and ships TypeScript types. It automatically reads tsconfig.json aliases and sorts imports into a fixed order: side effects, node modules, absolute non-aliased, aliased (from tsconfig and extraAliases), relative, and bottom aliases. Supports custom ordering via importSort options, including cache strategy, wildcard placement, and ignored/bottom aliases. Differentiators: minimal setup compared to @trivago/prettier-plugin-sort-imports, automatic alias resolution from tsconfig, and no additional configuration required for most projects. Release cadence is irregular; maintained by community.
Common errors
error Cannot find module 'prettier-plugin-sorted' ↓
cause Plugin not installed or not in node_modules.
fix
Run: npm install --save-dev prettier-plugin-sorted
error Error: Couldn't resolve plugin "prettier-plugin-sorted" ↓
cause Prettier cannot find the plugin; may be missing from node_modules or not configured correctly.
fix
Ensure plugin is installed and listed in Prettier config file (.prettierrc, .prettierrc.json, or prettier key in package.json).
Warnings
gotcha Plugin only works with Prettier v2.x; not compatible with Prettier v3. ↓
fix Use peer dependency prettier@^2.0.0. If using Prettier v3, consider @trivago/prettier-plugin-sort-imports.
deprecated The `importSort` configuration object is non-standard and may be removed in a future major version. ↓
fix Monitor changelog; prefer explicit plugin options if introduced.
Install
npm install prettier-plugin-sorted yarn add prettier-plugin-sorted pnpm add prettier-plugin-sorted Imports
- prettier-plugin-sorted wrong
require('prettier-plugin-sorted') // Not a direct import; it's a Prettier plugincorrect// Add to .prettierrc: { "plugins": ["prettier-plugin-sorted"] } - importSort wrong
import { importSort } from 'prettier-plugin-sorted' // Not exportedcorrect// Add to package.json: "importSort": { ".js, .ts": { "options": { ... } } }
Quickstart
// 1. Install
npm install --save-dev prettier-plugin-sorted prettier
// 2. Add to .prettierrc.json:
{
"plugins": ["prettier-plugin-sorted"]
}
// 3. Format files:
// Test with: npx prettier --write src/**/*.ts
// Example input (src/example.ts):
import './side-effect';
import { join } from 'path';
import Bar from './bar';
import { foo } from '../foo';
import React from 'react';
// Output after formatting:
import './side-effect';
import { join } from 'path';
import React from 'react';
import { foo } from '../foo';
import Bar from './bar';