Registry / devops / prettier-plugin-pkgsort

prettier-plugin-pkgsort

JSON →
library0.3.0jsnpmunverified

Prettier plugin that sorts package.json keys and fields using prettier-package-json. Current stable version 0.3.0 requires Prettier ^3.0.0 as a peer dependency. It provides consistent key ordering, sensible script sorting, expand/contract for author/contributors, and file field filtering/sorting. Ships TypeScript types. Released under MIT license.

npm install prettier-plugin-pkgsort
INSTALL
IMPORT
SIG · PRETTIER-PLUGIN-PK
P
prettier-plugin-pkgsort
devopsjavascriptv0.3.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.

default
plugins: [require.resolve('prettier-plugin-pkgsort')] in .prettierrc.js
plugins: ['prettier-plugin-pkgsort'] (CommonJS resolve may fail)
Use require.resolve for reliable resolution in CommonJS Prettier configs
module
import prettierPluginPkgsort from 'prettier-plugin-pkgsort'; plugins: [prettierPluginPkgsort]
const prettierPluginPkgsort = require('prettier-plugin-pkgsort'); (no default export in ESM)
Plugin is ESM-only. Use ESM import syntax or require.resolve for CJS configs.
type
import type { Plugin } from 'prettier'; import prettierPluginPkgsort from 'prettier-plugin-pkgsort'; const plugin: Plugin = prettierPluginPkgsort;
TypeScript types are provided; import type for plugin type if needed.

Configure Prettier to use prettier-plugin-pkgsort with custom expandUsers and keyOrder options.

// .prettierrc.cjs (CommonJS) module.exports = { plugins: [require.resolve('prettier-plugin-pkgsort')], pkgsortExpandUsers: true, pkgsortKeyOrder: ['name', 'version', 'description', 'main', 'scripts', 'dependencies', 'devDependencies'], };
Debug
Known issues
breakingVersion 0.2.0 dropped support for Prettier 2; requires Prettier ^3.0.0.
fix
Upgrade Prettier to version 3.x. If stuck on Prettier 2, use version 0.1.x.
affects: >=0.2.0
deprecatedCommonJS require() of the package directly may not work in v0.2.1+. Package became ESM-only.
fix
Use import expression or require.resolve in CommonJS configs: plugins: [require.resolve('prettier-plugin-pkgsort')]
affects: >=0.2.1
gotchaOptions like `pkgsortExpandUsers` and `pkgsortKeyOrder` must be placed in Prettier config, not in plugin options.
fix
Add options directly to the Prettier config object with the `pkgsort` prefix. Do not nest under plugin options.
affects: all
gotchaPlugin identifies package.json files by filename only. If your file has a different name (e.g., .package.json), it will not be processed.
fix
Rename file to package.json or use Prettier's file match patterns to include it.
affects: all
Errors
Common errors & fixes
Error: Cannot find module 'prettier-plugin-pkgsort'
Missing package installation or incorrect module resolution
fix
Run `npm install prettier-plugin-pkgsort --save-dev` and ensure node_modules is present. Use require.resolve in config.
TypeError: Cannot read properties of undefined (reading 'plugins')
Prettier config module.exports returns undefined or invalid object
fix
Ensure config exports an object correctly: module.exports = { plugins: [...] };
Error: Could not resolve 'prettier-plugin-pkgsort' from '...'
Using string literal instead of require.resolve in CommonJS config
fix
Change plugins: ['prettier-plugin-pkgsort'] to plugins: [require.resolve('prettier-plugin-pkgsort')]
Upgrade
Version history
0.3.0latest on npm
Audit
Dependencies
prettieroptionalpeer dependency required to run
Agent activity
4 hits · last 30 days
node
4
Resources
prettier-plugin-pkgsort — npm install prettier-plugin-pkgsort · libregistry