{"id":20427,"library":"prettier-plugin-sort-package-json","title":"prettier-plugin-sort-package-json","description":"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.","status":"active","version":"1.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/ignatiusmb/prettier-plugin-suite","tags":["javascript","prettier","plugin","sort","package.json","typescript"],"install":[{"cmd":"npm install prettier-plugin-sort-package-json","lang":"bash","label":"npm"},{"cmd":"yarn add prettier-plugin-sort-package-json","lang":"bash","label":"yarn"},{"cmd":"pnpm add prettier-plugin-sort-package-json","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency — must be installed separately","package":"prettier","optional":false}],"imports":[{"note":"Plugin is loaded by Prettier via string name in config, not imported directly in code.","wrong":"// Using require in config file: const plugin = require('prettier-plugin-sort-package-json') — not supported","symbol":"plugin","correct":"// In .prettierrc: { \"plugins\": [\"prettier-plugin-sort-package-json\"] }"},{"note":"The custom parser 'sort-package-json' is used for package.json-like files; the default parser for package.json is automatically applied.","wrong":"// Using 'json' or 'json-stringify' parser for package.json — will not sort","symbol":"parser","correct":"// In .prettierrc: { \"overrides\": [{ \"files\": [\"pkg.json\"], \"options\": { \"parser\": \"sort-package-json\" } }] }"},{"note":"This is purely a Prettier plugin; there are no programmatic exports.","wrong":"import { sortPackageJson } from 'prettier-plugin-sort-package-json' — no such export","symbol":"sort-package-json","correct":"// Not imported directly; used as Prettier parser string"}],"quickstart":{"code":"// 1. Install\nnpm install -D prettier prettier-plugin-sort-package-json\n\n// 2. Create .prettierrc\n{\n  \"plugins\": [\"prettier-plugin-sort-package-json\"]\n}\n\n// 3. Run Prettier\nnpx prettier --write package.json\n\n// package.json will now have sorted keys:\n{\n  \"name\": \"my-package\",\n  \"version\": \"1.0.0\",\n  \"description\": \"...\",\n  \"main\": \"index.js\",\n  \"scripts\": {\n    \"build\": \"tsc\",\n    \"test\": \"jest\"\n  },\n  \"dependencies\": {},\n  \"devDependencies\": {}\n}","lang":"typescript","description":"Installs the plugin, adds it to Prettier config, and formats package.json with automatic sorting."},"warnings":[{"fix":"No action needed — order is now consistent with npm docs. Run Prettier to update files.","message":"Version 0.2.0 reordered 'license' and 'funding' keys — existing files may have different order after update.","severity":"breaking","affected_versions":">=0.2.0"},{"fix":"Upgrade to latest: npm install -D prettier-plugin-sort-package-json@latest","message":"Versions below 1.0.0 are deprecated; v1.0.0 added full support for all npm v11 keys.","severity":"deprecated","affected_versions":"<1.0.0"},{"fix":"Add overrides to .prettierrc: { \"files\": [\"pkg.json\"], \"options\": { \"parser\": \"sort-package-json\" } }","message":"The plugin only sorts package.json by default; for other .json files you must specify a custom parser in overrides.","severity":"gotcha","affected_versions":">=1.1.0"},{"fix":"Ensure Prettier version is ^3.0.0: npm install -D prettier@3","message":"The plugin requires Prettier v3 or higher (peer dependency).","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use --plugin=prettier-plugin-sort-package-json or just add to config.","message":"If you use Prettier's CLI --plugin flag, ensure the plugin is installed and the flag points to the correct path.","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":"npm install -D prettier-plugin-sort-package-json","cause":"Plugin not installed or not in node_modules","error":"Cannot find module 'prettier-plugin-sort-package-json'"},{"fix":"Add \"plugins\": [\"prettier-plugin-sort-package-json\"] to Prettier config","cause":"Using parser 'sort-package-json' without adding the plugin to plugins list","error":"Error: Invalid parser 'sort-package-json'. Did you mean 'json'?"},{"fix":"Update Prettier to v3 or higher: npm install -D prettier@latest","cause":"Prettier version is too old (< 3.0.0) and doesn't support plugins","error":"Unsupported option \"plugins\" in Prettier config (prettier-plugin-sort-package-json)."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}