Registry / devops / prettier-plugin-package2

prettier-plugin-package2

JSON →
library0.6.0jsnpmunverified

An opinionated Prettier plugin for formatting package.json files. Version 0.6.0 (stable) requires Prettier ^2.0.0 and Node >=10.13.0. Sorts package.json keys in a conventional order (inspired by @sindresorhus) and alphabetically orders keys in engines, files, and scripts sections. Unlike alternatives like prettier-plugin-package, it enforces a specific top-level key ordering and handles unknown keys by appending alphabetically. Released under MPL-2.0.

npm install prettier-plugin-package2
INSTALL
IMPORT
SIG · PRETTIER-PLUGIN-PA
P
prettier-plugin-package2
devopsjavascriptv0.6.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

default export (plugin)
// No explicit import; Prettier auto-discovers plugins in node_modules // Or use: npx prettier --write package.json
const plugin = require('prettier-plugin-package2')
Prettier plugins are automatically loaded when installed. No manual import required.
none (config only)
// In .prettierrc: { "plugins": ["prettier-plugin-package2"] }
const prettierPluginPackage2 = require('prettier-plugin-package2')
Plugins are referenced by package name in Prettier configuration, not imported directly.

Install the plugin as a dev dependency with Prettier, then format package.json using Prettier's CLI.

// Install npm install --save-dev prettier prettier-plugin-package2 // Run formatter npx prettier --write package.json // Or add to scripts in package.json: { "scripts": { "format": "prettier --write \"**/*.json\"" } }
Debug
Known issues
gotchaPlugin requires Prettier v2.0.0+; compatible with v3? Not tested.
fix
Ensure Prettier version is >=2.0.0 and <3.0.0 (if not tested).
affects: >=0.1.0
gotchaTop-level key ordering is opinionated and may conflict with other tools that sort package.json.
fix
Disable plugin if you need a different order, or use another plugin like prettier-plugin-package (which sorts alphabetically).
affects: >=0.1.0
gotchaUnknown top-level keys are appended alphabetically; this may not be desired for custom keys.
fix
If you have custom keys that should appear in a specific position, consider using a pre-commit hook or manual ordering.
affects: >=0.1.0
Errors
Common errors & fixes
Error: Cannot find module 'prettier-plugin-package2'
Plugin not installed or Prettier cannot resolve it.
fix
Install as dev dependency: npm install --save-dev prettier-plugin-package2
Error: Unsupported Prettier version. Expected >2.0.0
prettier-plugin-package2 requires Prettier v2.0.0+.
fix
Upgrade Prettier: npm update prettier or npm install prettier@^2.0.0
Configuration error: Cannot find module 'prettier'
Prettier is not installed as a peer dependency.
fix
Install Prettier: npm install --save-dev prettier
Upgrade
Version history
0.6.0latest on npm
Audit
Dependencies
prettierrequiredpeer dependency; plugin requires Prettier v2.0.0+
Agent activity
4 hits · last 30 days
node
4
Resources
prettier-plugin-package2 — npm install prettier-plugin-package2 · libregistry