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.
npm install prettier-plugin-sort-importsVerified import paths — ran on the pinned version, not inferred.
Demonstrates installation, configuration with import type ordering and line-length sorting, and the resulting import order change.
Add 'plugins: ["./node_modules/prettier-plugin-sort-imports/dist/index.js"]' to Prettier config
Use only 'all' alone, or specify an array without 'all' (e.g., ['NPMPackages', 'localImports'])
Remove pluginSearchDirs and directly reference the plugin path in the plugins array
Consider using alphabetical sorting if you want predictable order based on module name
Set stripNewlines to false if you want to preserve blank lines between import blocks
Ensure prettier-plugin-sort-imports is installed and referenced in plugins array (for Prettier 3) or pluginSearchDirs (for Prettier 2)
Use only 'all' alone, or specify NPMPackages with one of the local import types (e.g., ['NPMPackages', 'localImports'])
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