Registry / devops / prettier-plugin-sort-package-json

prettier-plugin-sort-package-json

JSON →
library1.1.0jsnpmunverified

Prettier plugin that automatically sorts the keys in package.json files. Current stable version is 1.1.0, released in April 2025. This plugin is a zero-dependency, opinionated tool that works out of the box with no configuration. It supports all keys defined in the npm v11 package.json documentation and also provides a custom parser for sorting package.json-like files. Unlike alternatives (e.g., sort-package-json standalone CLI), it integrates directly into Prettier's workflow, enabling auto-formatting on save and consistent sorting across teams without extra scripts.

npm install prettier-plugin-sort-package-json
INSTALL
IMPORT
SIG · PRETTIER-PLUGIN-SO
P
prettier-plugin-sort-package-json
devopsjavascriptv1.1.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
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 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

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

plugin
✓ // In .prettierrc: { "plugins": ["prettier-plugin-sort-package-json"] }
✗ // Using require in config file: const plugin = require('prettier-plugin-sort-package-json') — not supported
Plugin is loaded by Prettier via string name in config, not imported directly in code.
parser
✓ // In .prettierrc: { "overrides": [{ "files": ["pkg.json"], "options": { "parser": "sort-package-json" } }] }
✗ // Using 'json' or 'json-stringify' parser for package.json — will not sort
The custom parser 'sort-package-json' is used for package.json-like files; the default parser for package.json is automatically applied.
sort-package-json
✓ // Not imported directly; used as Prettier parser string
✗ import { sortPackageJson } from 'prettier-plugin-sort-package-json' — no such export
This is purely a Prettier plugin; there are no programmatic exports.

Installs the plugin, adds it to Prettier config, and formats package.json with automatic sorting.

// 1. Install npm install -D prettier prettier-plugin-sort-package-json // 2. Create .prettierrc { "plugins": ["prettier-plugin-sort-package-json"] } // 3. Run Prettier npx prettier --write package.json // package.json will now have sorted keys: { "name": "my-package", "version": "1.0.0", "description": "...", "main": "index.js", "scripts": { "build": "tsc", "test": "jest" }, "dependencies": {}, "devDependencies": {} }
Debug
Known issues
breakingVersion 0.2.0 reordered 'license' and 'funding' keys — existing files may have different order after update.
fix
No action needed — order is now consistent with npm docs. Run Prettier to update files.
affects: >=0.2.0
deprecatedVersions below 1.0.0 are deprecated; v1.0.0 added full support for all npm v11 keys.
fix
Upgrade to latest: npm install -D prettier-plugin-sort-package-json@latest
affects: <1.0.0
gotchaThe plugin only sorts package.json by default; for other .json files you must specify a custom parser in overrides.
fix
Add overrides to .prettierrc: { "files": ["pkg.json"], "options": { "parser": "sort-package-json" } }
affects: >=1.1.0
gotchaThe plugin requires Prettier v3 or higher (peer dependency).
fix
Ensure Prettier version is ^3.0.0: npm install -D prettier@3
affects: >=1.0.0
gotchaIf you use Prettier's CLI --plugin flag, ensure the plugin is installed and the flag points to the correct path.
fix
Use --plugin=prettier-plugin-sort-package-json or just add to config.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'prettier-plugin-sort-package-json'
Plugin not installed or not in node_modules
fix
npm install -D prettier-plugin-sort-package-json
Error: Invalid parser 'sort-package-json'. Did you mean 'json'?
Using parser 'sort-package-json' without adding the plugin to plugins list
fix
Add "plugins": ["prettier-plugin-sort-package-json"] to Prettier config
Unsupported option "plugins" in Prettier config (prettier-plugin-sort-package-json).
Prettier version is too old (< 3.0.0) and doesn't support plugins
fix
Update Prettier to v3 or higher: npm install -D prettier@latest
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies
prettierrequiredpeer dependency — must be installed separately
Agent activity
2 hits · last 30 days
node
2
Resources
prettier-plugin-sort-package-json — npm install prettier-plugin-sort-package-json · libregistry