{"id":20423,"library":"prettier-plugin-sort-imports","title":"prettier-plugin-sort-imports","description":"A Prettier plugin that sorts import statements by line length or alphabetically. Currently at version 1.8.11 with monthly releases. It automatically loads into Prettier, sorting by line length by default. Differentiates itself from alternatives by offering line-length sorting (not just alphabetical) and import-type grouping (NPM vs local, type vs value). Requires TypeScript >4.0.0 as a peer dependency. Supports both Prettier 2 and 3 with separate entry points.","status":"active","version":"1.8.11","language":"javascript","source_language":"en","source_url":"https://github.com/SanderRonde/prettier-plugin-sort-imports","tags":["javascript","prettier","plugin","sort","import","typescript"],"install":[{"cmd":"npm install prettier-plugin-sort-imports","lang":"bash","label":"npm"},{"cmd":"yarn add prettier-plugin-sort-imports","lang":"bash","label":"yarn"},{"cmd":"pnpm add prettier-plugin-sort-imports","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required as a peer dependency for type import detection and sorting","package":"typescript","optional":false}],"imports":[{"note":"The plugin is auto-discovered by Prettier; do not import it in code. For Prettier 3, reference it in plugins array as a path.","wrong":"const plugin = require('prettier-plugin-sort-imports')","symbol":"default export","correct":"auto-loaded by Prettier; no explicit import needed"},{"note":"Set in .prettierrc or prettier.config.js; valid values are 'lineLength' (default) and 'alphabetical'.","wrong":"sortingMethod: 'length'","symbol":"sortingMethod option","correct":"sortingMethod: 'lineLength' or 'alphabetical' in Prettier config"},{"note":"Use the exact strings: 'NPMPackages', 'localImportsValue', 'localImportsType', 'localImports', or 'all'. Cannot mix 'all' with others.","wrong":"importTypeOrder: ['npm', 'local']","symbol":"importTypeOrder option","correct":"importTypeOrder: ['NPMPackages', 'localImports']"}],"quickstart":{"code":"// Install: npm install --save-dev prettier prettier-plugin-sort-imports\n// prettier.config.js\nmodule.exports = {\n  sortingMethod: 'lineLength',\n  importTypeOrder: ['NPMPackages', 'localImports'],\n  plugins: ['./node_modules/prettier-plugin-sort-imports/dist/index.js'],\n};\n\n// Before\nimport z from 'zoo';\nimport a from './local';\nimport b from 'bar';\nimport type { C } from './types';\n\n// After formatting with Prettier\nimport b from 'bar';\nimport z from 'zoo';\nimport a from './local';\nimport type { C } from './types';","lang":"javascript","description":"Demonstrates installation, configuration with import type ordering and line-length sorting, and the resulting import order change."},"warnings":[{"fix":"Add 'plugins: [\"./node_modules/prettier-plugin-sort-imports/dist/index.js\"]' to Prettier config","message":"Plugin must be manually added to plugins array for Prettier 3; auto-discovery may not work","severity":"gotcha","affected_versions":">=1.8.0"},{"fix":"Use only 'all' alone, or specify an array without 'all' (e.g., ['NPMPackages', 'localImports'])","message":"Cannot combine 'all' import type with other types in importTypeOrder","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Remove pluginSearchDirs and directly reference the plugin path in the plugins array","message":"pluginSearchDirs option is deprecated in Prettier 3; use plugins array instead","severity":"deprecated","affected_versions":">=1.7.0"},{"fix":"Consider using alphabetical sorting if you want predictable order based on module name","message":"Line-length sorting uses the entire import statement length, not just the source path","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Set stripNewlines to false if you want to preserve blank lines between import blocks","message":"Newlines between import groups are stripped when stripNewlines is true, which may break intentional grouping","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Ensure prettier-plugin-sort-imports is installed and referenced in plugins array (for Prettier 3) or pluginSearchDirs (for Prettier 2)","cause":"Plugin not loaded or not properly configured in Prettier config","error":"Cannot read properties of undefined (reading 'sortingMethod')"},{"fix":"Use only 'all' alone, or specify NPMPackages with one of the local import types (e.g., ['NPMPackages', 'localImports'])","cause":"importTypeOrder contains incomplete or incompatible types","error":"Error: Invalid importTypeOrder array: must contain either 'all' or a combination of 'NPMPackages', 'localImports', 'localImportsValue', 'localImportsType'"},{"fix":"Use the correct plugin path: './node_modules/prettier-plugin-sort-imports/dist/index.js' for Prettier 3, './node_modules/prettier-plugin-sort-imports/dist/index.2.js' for Prettier 2","cause":"Prettier version mismatch (trying to use Prettier 3 entry point with Prettier 2)","error":"TypeError: Cannot read properties of undefined (reading 'some')"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}