Registry / devops / prettier-plugin-package

prettier-plugin-package

JSON →
library2.0.0jsnpmunverified

An opinionated package.json formatter plugin for Prettier, enforcing a consistent key ordering style popularized by Sindre Sorhus. v2.0.0 requires Node >=20.19.0 and Prettier ^3.0.0. It sorts top-level keys, and alphabetizes scripts, files, and engines. Differentiates from other package.json formatters by its strict opinionated ordering and automatic key classification. Released under MPL-2.0, maintained by shellscape, with monthly releases.

npm install prettier-plugin-package
INSTALL
IMPORT
SIG · PRETTIER-PLUGIN-PA
P
prettier-plugin-package
devopsjavascriptv2.0.0
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.

prettier-plugin-package
// No explicit import needed; Prettier auto-loads plugins
import plugin from 'prettier-plugin-package' // Incorrect: plugins are auto-discovered
Since v2, Prettier automatically loads plugins from node_modules; no configuration required.
Prettier custom config (plugin)
// prettier.config.js module.exports = { plugins: ['prettier-plugin-package'] }
const plugin = require('prettier-plugin-package'); module.exports = { plugins: [plugin] } // Works but redundant; string form is preferred
Plugins can be specified as strings or objects; string is idiomatic.
Plugin options (none)
// No plugin-specific options
// prettier.config.js module.exports = { plugins: ['prettier-plugin-package'], packageSortOrder: 'custom' } // No such option
The plugin does not accept any options; behavior is fully opinionated.

Demonstrates automatic sorting of keys and scripts in package.json after running Prettier with the plugin.

// Install: npm install --save-dev prettier prettier-plugin-package // package.json (initial state) { "devDependencies": { "prettier": "^3.0.0" }, "scripts": { "build": "echo build", "test": "echo test", "lint": "echo lint" }, "description": "My package", "name": "my-pkg", "version": "1.0.0" } // After running: npx prettier --write package.json // The keys will be reordered per the plugin's sort order: { "name": "my-pkg", "version": "1.0.0", "description": "My package", "scripts": { "build": "echo build", "lint": "echo lint", "test": "echo test" }, "devDependencies": { "prettier": "^3.0.0" } }
Debug
Known issues
breakingNode.js >=20.19.0 required (v2 release)
fix
Upgrade Node.js to v20.19.0 or later, or use prettier-plugin-package@1.4.0 for Node 14+ and Prettier v2.
affects: >=2.0.0
breakingPrettier v3 only (v2 release). v1.x and v2.x not supported.
fix
Use prettier-plugin-package@1.4.0 for Prettier v2, or @0.3.1 for Prettier v1.
affects: >=2.0.0
breakingPlugin no longer uses preprocess; switched to parser in v0.3.0. Behavior may differ.
fix
Ensure you use Prettier v2+ and run via standard prettier --write. No migration steps required.
affects: >=0.3.0
gotchaUnknown keys are sorted alphabetically after known keys. This may reorder unsorted custom keys unexpectedly.
fix
Review resulting package.json order; if custom keys appear in unexpected order, consider renaming keys to match alphabetical order or accept the opinionated sort.
affects: >=0.0.0
gotchaThe files array gets reordered: alphabetical, with negations kept together, and README.md / LICENSE appended if present.
fix
Verify that your files array after formatting includes all intended entries; the plugin ensures README.md and LICENSE are last if present.
affects: >=0.3.0
Errors
Common errors & fixes
Cannot find module 'prettier-plugin-package'
Plugin not installed or not in node_modules when running Prettier.
fix
Run npm install --save-dev prettier-plugin-package. Ensure prettier is also installed.
Error: No parser and no file path given, couldn't infer a parser.
Prettier invoked without a file; plugin only formats package.json, not other files.
fix
Run Prettier explicitly on package.json: npx prettier --write package.json
prettier-plugin-package: Node.js version 20.19.0 is required. Current version: ...
Node.js version below 20.19.0 with plugin v2.
fix
Upgrade Node.js to >=20.19.0 or downgrade plugin to v1.4.0 using npm install prettier-plugin-package@1.4.0 --save-dev
prettier-plugin-package: prettier version ^3.0.0 is required.
Prettier v2 is installed but plugin v2 requires v3.
fix
Install prettier v3: npm install prettier@^3.0.0 or downgrade plugin to v1.4.0 with npm install prettier-plugin-package@1.4.0 --save-dev
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
prettierrequiredPeer dependency; required at runtime as a plugin host
Agent activity
2 hits · last 30 days
node
2
Resources
prettier-plugin-package — npm install prettier-plugin-package · libregistry