Prettier Plugin Package Perfection
raw JSON → 1.1.0 verified Sat Apr 25 auth: no javascript
A Prettier plugin that formats package.json files using the prettier-package-json library for consistent ordering and styling. Version 1.1.0 is the latest stable version, released August 2022 with limited update activity. It requires Prettier ≥2.x and Node.js ≥14.18.0. Differentiators include automatic key sorting, customizable order via options, and seamless integration with Prettier workflows, unlike standalone formatters.
Common errors
error Error: Cannot find module 'prettier-plugin-package-perfection' ↓
cause Plugin not installed or not in node_modules.
fix
Run 'npm install --save-dev prettier-plugin-package-perfection' and ensure it's in devDependencies.
error Error: Invalid plugin configuration: 'packagePerfection' option not recognized ↓
cause Plugin not added to Prettier's plugins array.
fix
Add '"plugins": ["prettier-plugin-package-perfection"]' to your .prettierrc file.
error Error: Unknown option 'packagePerfection.sortAz' ↓
cause Option name typo or not supported in this version.
fix
Check the plugin's README for supported options; correct spelling.
Warnings
breaking Requires Node.js >=14.18.0; older versions will fail to load the plugin. ↓
fix Update Node.js to >=14.18.0.
deprecated Plugin uses prettier-package-json v2 which may deprecate some options; refer to their docs. ↓
fix Check prettier-package-json documentation for option changes.
gotcha The plugin only runs on files named 'package.json'. Other files matching the pattern will not be affected. ↓
fix Ensure your target file is exactly named 'package.json'.
gotcha Some custom Prettier config formats (e.g., YAML) may not parse the plugin correctly; stick to JSON or JS config. ↓
fix Use JSON or JavaScript Prettier configuration files.
Install
npm install prettier-plugin-package-perfection yarn add prettier-plugin-package-perfection pnpm add prettier-plugin-package-perfection Imports
- default wrong
NonecorrectNo explicit import needed; Prettier auto-loads plugins - options wrong
{"plugins": ["prettier-plugin-package-perfection"] }correct// .prettierrc { "plugins": ["prettier-plugin-package-perfection"] } - types wrong
const { PackagePerfectionOptions } = require('prettier-plugin-package-perfection')correctimport type { PackagePerfectionOptions } from 'prettier-plugin-package-perfection'
Quickstart
// Install dependencies
// npm install --save-dev prettier prettier-plugin-package-perfection
// .prettierrc (JSON)
{
"plugins": ["prettier-plugin-package-perfection"],
"packagePerfection": {
"sortAz": true,
"sortScripts": false
}
}
// Run Prettier on package.json
// npx prettier --write package.json