Prettier Plugin PkgJson

raw JSON →
0.3.0 verified Sat Apr 25 auth: no javascript

Prettier plugin for clean and meaningful formatting of package.json files. Version 0.3.0 is the latest stable release. It sorts keys in a logical order, formats JSON consistently, and integrates seamlessly with Prettier. No dependencies. Actively maintained as part of the tunnckoCore opensource monorepo.

error Error: Cannot find module 'prettier-plugin-pkgjson'
cause Plugin not installed or not in node_modules.
fix
Run npm install prettier-plugin-pkgjson --save-dev
error Invalid option for rule 'prettier/prettier': Expected a string but received an object
cause Misconfiguring ESLint with prettier-plugin-pkgjson.
fix
Ensure prettier-plugin-pkgjson is listed in .prettierrc plugins array, not in ESLint config.
error Error: Package subpath './package.json' is not defined by "exports" in .../prettier-plugin-pkgjson/package.json
cause Using older Node.js (<12) or misconfigured imports.
fix
Use Node.js >=10.13; if issue persists, check that Prettier resolves the plugin correctly.
gotcha Plugin requires Prettier v2.x or later; not compatible with Prettier v1.x.
fix Update Prettier to >=2.0.0.
gotcha Only works on package.json files; other JSON files are unaffected.
fix Use only for package.json; for other JSON files use other plugins.
gotcha Plugin must be explicitly added to Prettier's plugins array; not auto-detected.
fix Add "prettier-plugin-pkgjson" to plugins array in Prettier config.
npm install prettier-plugin-pkgjson
yarn add prettier-plugin-pkgjson
pnpm add prettier-plugin-pkgjson

Example .prettierrc configuration to enable the plugin and format package.json files.

{
  "semi": false,
  "singleQuote": true,
  "tabWidth": 2,
  "trailingComma": "none",
  "plugins": ["prettier-plugin-pkgjson"]
}