Registry / devops / prettier-plugin-sort

prettier-plugin-sort

JSON →
library0.1.0jsnpmunverified

An all-in-one Prettier plugin for sorting imports, package.json keys, and export statements. Version 0.1.0 is current (May 2025), with a rapid release cadence focused on stability and performance. Key differentiators: zero runtime dependencies, TypeScript support, and a modular approach inspired by eslint-plugin-import/order. Supports import attributes (ES2023), type import styling options (separate, inline-first, inline-last, mixed), and respects side-effect imports as chunk boundaries. Ships type definitions. Peer dependency on Prettier >=3.0.0.

npm install prettier-plugin-sort
INSTALL
IMPORT
SIG · PRETTIER-PLUGIN-SO
P
prettier-plugin-sort
devopsjavascriptv0.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import prettierPluginSort from 'prettier-plugin-sort'
const prettierPluginSort = require('prettier-plugin-sort')
The package is ESM-only; CommonJS require() will fail. If using CommonJS, use dynamic import: const { default: prettierPluginSort } = await import('prettier-plugin-sort').
sortImports
import { sortImports } from 'prettier-plugin-sort'
import sortImports from 'prettier-plugin-sort'
sortImports is a named export, not a default export. Available in v0.1.0+. For programmatic use.
sortPackageJson
import { sortPackageJson } from 'prettier-plugin-sort'
import { sortPackage } from 'prettier-plugin-sort'
Exact name is sortPackageJson (not sortPackage). Exported as a named function.

Demonstrates installation, Prettier config activation, default import sorting behavior, and CLI usage.

// Install: npm i -D prettier prettier-plugin-sort // .prettierrc { "plugins": ["prettier-plugin-sort"], "importOrderGroups": ["builtin", "external", "parent", "sibling", "index"], "importOrderSeparation": true, "importOrderTypeImports": "separate", "importOrderMergeDuplicates": true } // Example: sort imports in a JS/TS file // Input: // import App from './App.tsx'; // import fs from 'node:fs'; // import lodash from 'lodash'; // import path from 'node:path'; // import react from 'react'; // Run: npx prettier --write file.ts // Output: // import fs from 'node:fs'; // import path from 'node:path'; // // import lodash from 'lodash'; // import react from 'react'; // // import App from './App.tsx';
Debug
Known issues
breakingIn v0.1.0, side-effect imports are no longer moved; they act as chunk boundaries. Previously they would be reordered along with other imports.
fix
If your code relies on side-effect imports being sorted, set importOrderSideEffects: "move" (not yet implemented). Otherwise, no action needed.
affects: >=0.1.0
breakingIn v0.0.3, the plugin gained support for ES2023 import attributes (with { type: 'json' }). Older versions silently dropped such attributes.
fix
Upgrade to v0.0.3 or later to preserve import attributes.
affects: <0.0.3
gotchaThe internal pattern detection uses hard-coded prefixes (/ , ~ , @/). It does not read tsconfig paths or bundler aliases.
fix
Use one of the recognized prefixes for internal modules, or wait for custom pattern support (future release).
affects: >=0.0.1
gotchaCommonJS require() will throw an error because the package is ESM-only.
fix
Use dynamic import or convert your project to ESM. If using CommonJS, use await import('prettier-plugin-sort').
affects: >=0.0.1
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/node_modules/prettier-plugin-sort/dist/index.js from /path/to/.prettierrc.js not supported.
prettier-plugin-sort is ESM-only; cannot be required from a CommonJS config file.
fix
Rename .prettierrc.js to .prettierrc.mjs, or use a JSON config file.
SyntaxError: Unexpected token 'export'
Prettier version <3.0.0 does not support the plugin API used by prettier-plugin-sort.
fix
Upgrade Prettier to >=3.0.0: npm i -D prettier@latest
Cannot read properties of undefined (reading 'sort')
The sort function is not found because the import path is wrong or the plugin is not properly loaded.
fix
Ensure 'prettier-plugin-sort' is listed in the plugins array of your Prettier config. Do not import it directly unless using programmatic API.
TypeError: Cannot set property 'importOrderSeparation' of undefined
The plugin options are being set before the plugins array is defined in the config.
fix
Move the 'plugins' array to the top level of your Prettier config, or use a valid JSON config format.
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies
prettierrequiredPeer dependency required as a plugin host; Prettier >=3.0.0 is needed.
Agent activity
3 hits · last 30 days
node
3
Resources
prettier-plugin-sort — npm install prettier-plugin-sort · libregistry