{"id":26102,"library":"prettier-plugin-sort","title":"prettier-plugin-sort","description":"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.","status":"active","version":"0.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/xueelf/prettier-plugin-sort","tags":["javascript","imports","order","organize","package.json","plugin","prettier","prettier-plugin","sort","typescript"],"install":[{"cmd":"npm install prettier-plugin-sort","lang":"bash","label":"npm"},{"cmd":"yarn add prettier-plugin-sort","lang":"bash","label":"yarn"},{"cmd":"pnpm add prettier-plugin-sort","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency required as a plugin host; Prettier >=3.0.0 is needed.","package":"prettier","optional":false}],"imports":[{"note":"The package is ESM-only; CommonJS require() will fail. If using CommonJS, use dynamic import: const { default: prettierPluginSort } = await import('prettier-plugin-sort').","wrong":"const prettierPluginSort = require('prettier-plugin-sort')","symbol":"default","correct":"import prettierPluginSort from 'prettier-plugin-sort'"},{"note":"sortImports is a named export, not a default export. Available in v0.1.0+. For programmatic use.","wrong":"import sortImports from 'prettier-plugin-sort'","symbol":"sortImports","correct":"import { sortImports } from 'prettier-plugin-sort'"},{"note":"Exact name is sortPackageJson (not sortPackage). Exported as a named function.","wrong":"import { sortPackage } from 'prettier-plugin-sort'","symbol":"sortPackageJson","correct":"import { sortPackageJson } from 'prettier-plugin-sort'"}],"quickstart":{"code":"// Install: npm i -D prettier prettier-plugin-sort\n\n// .prettierrc\n{\n  \"plugins\": [\"prettier-plugin-sort\"],\n  \"importOrderGroups\": [\"builtin\", \"external\", \"parent\", \"sibling\", \"index\"],\n  \"importOrderSeparation\": true,\n  \"importOrderTypeImports\": \"separate\",\n  \"importOrderMergeDuplicates\": true\n}\n\n// Example: sort imports in a JS/TS file\n// Input:\n// import App from './App.tsx';\n// import fs from 'node:fs';\n// import lodash from 'lodash';\n// import path from 'node:path';\n// import react from 'react';\n// Run: npx prettier --write file.ts\n// Output:\n// import fs from 'node:fs';\n// import path from 'node:path';\n// \n// import lodash from 'lodash';\n// import react from 'react';\n// \n// import App from './App.tsx';","lang":"typescript","description":"Demonstrates installation, Prettier config activation, default import sorting behavior, and CLI usage."},"warnings":[{"fix":"If your code relies on side-effect imports being sorted, set importOrderSideEffects: \"move\" (not yet implemented). Otherwise, no action needed.","message":"In v0.1.0, side-effect imports are no longer moved; they act as chunk boundaries. Previously they would be reordered along with other imports.","severity":"breaking","affected_versions":">=0.1.0"},{"fix":"Upgrade to v0.0.3 or later to preserve import attributes.","message":"In v0.0.3, the plugin gained support for ES2023 import attributes (with { type: 'json' }). Older versions silently dropped such attributes.","severity":"breaking","affected_versions":"<0.0.3"},{"fix":"Use one of the recognized prefixes for internal modules, or wait for custom pattern support (future release).","message":"The internal pattern detection uses hard-coded prefixes (/ , ~ , @/). It does not read tsconfig paths or bundler aliases.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Use dynamic import or convert your project to ESM. If using CommonJS, use await import('prettier-plugin-sort').","message":"CommonJS require() will throw an error because the package is ESM-only.","severity":"gotcha","affected_versions":">=0.0.1"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Rename .prettierrc.js to .prettierrc.mjs, or use a JSON config file.","cause":"prettier-plugin-sort is ESM-only; cannot be required from a CommonJS config file.","error":"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."},{"fix":"Upgrade Prettier to >=3.0.0: npm i -D prettier@latest","cause":"Prettier version <3.0.0 does not support the plugin API used by prettier-plugin-sort.","error":"SyntaxError: Unexpected token 'export'"},{"fix":"Ensure 'prettier-plugin-sort' is listed in the plugins array of your Prettier config. Do not import it directly unless using programmatic API.","cause":"The sort function is not found because the import path is wrong or the plugin is not properly loaded.","error":"Cannot read properties of undefined (reading 'sort')"},{"fix":"Move the 'plugins' array to the top level of your Prettier config, or use a valid JSON config format.","cause":"The plugin options are being set before the plugins array is defined in the config.","error":"TypeError: Cannot set property 'importOrderSeparation' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}