Registry / devops / prettier-plugin-sort-imports

prettier-plugin-sort-imports

JSON →
library1.8.11jsnpmunverified

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-imports
INSTALL
IMPORT
SIG · PRETTIER-PLUGIN-SO
P
prettier-plugin-sort-imports
devopsjavascriptv1.8.11
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

default export
auto-loaded by Prettier; no explicit import needed
const plugin = require('prettier-plugin-sort-imports')
The plugin is auto-discovered by Prettier; do not import it in code. For Prettier 3, reference it in plugins array as a path.
sortingMethod option
sortingMethod: 'lineLength' or 'alphabetical' in Prettier config
sortingMethod: 'length'
Set in .prettierrc or prettier.config.js; valid values are 'lineLength' (default) and 'alphabetical'.
importTypeOrder option
importTypeOrder: ['NPMPackages', 'localImports']
importTypeOrder: ['npm', 'local']
Use the exact strings: 'NPMPackages', 'localImportsValue', 'localImportsType', 'localImports', or 'all'. Cannot mix 'all' with others.

Demonstrates installation, configuration with import type ordering and line-length sorting, and the resulting import order change.

// Install: npm install --save-dev prettier prettier-plugin-sort-imports // prettier.config.js module.exports = { sortingMethod: 'lineLength', importTypeOrder: ['NPMPackages', 'localImports'], plugins: ['./node_modules/prettier-plugin-sort-imports/dist/index.js'], }; // Before import z from 'zoo'; import a from './local'; import b from 'bar'; import type { C } from './types'; // After formatting with Prettier import b from 'bar'; import z from 'zoo'; import a from './local'; import type { C } from './types';
Debug
Known issues
gotchaPlugin must be manually added to plugins array for Prettier 3; auto-discovery may not work
fix
Add 'plugins: ["./node_modules/prettier-plugin-sort-imports/dist/index.js"]' to Prettier config
affects: >=1.8.0
gotchaCannot combine 'all' import type with other types in importTypeOrder
fix
Use only 'all' alone, or specify an array without 'all' (e.g., ['NPMPackages', 'localImports'])
affects: >=1.0.0
deprecatedpluginSearchDirs option is deprecated in Prettier 3; use plugins array instead
fix
Remove pluginSearchDirs and directly reference the plugin path in the plugins array
affects: >=1.7.0
gotchaLine-length sorting uses the entire import statement length, not just the source path
fix
Consider using alphabetical sorting if you want predictable order based on module name
affects: >=1.0.0
gotchaNewlines between import groups are stripped when stripNewlines is true, which may break intentional grouping
fix
Set stripNewlines to false if you want to preserve blank lines between import blocks
affects: >=1.0.0
Errors
Common errors & fixes
Cannot read properties of undefined (reading 'sortingMethod')
Plugin not loaded or not properly configured in Prettier config
fix
Ensure prettier-plugin-sort-imports is installed and referenced in plugins array (for Prettier 3) or pluginSearchDirs (for Prettier 2)
Error: Invalid importTypeOrder array: must contain either 'all' or a combination of 'NPMPackages', 'localImports', 'localImportsValue', 'localImportsType'
importTypeOrder contains incomplete or incompatible types
fix
Use only 'all' alone, or specify NPMPackages with one of the local import types (e.g., ['NPMPackages', 'localImports'])
TypeError: Cannot read properties of undefined (reading 'some')
Prettier version mismatch (trying to use Prettier 3 entry point with Prettier 2)
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
Upgrade
Version history
1.8.11latest on npm
Audit
Dependencies
typescriptrequiredRequired as a peer dependency for type import detection and sorting
Agent activity
4 hits · last 30 days
node
4
Resources
prettier-plugin-sort-imports — npm install prettier-plugin-sort-imports · libregistry