Skip to content

consistent-package-manager-declaration

🔧💡 This rule is automatically fixable by the --fix CLI option and manually fixable by editor suggestions.

This rule enforces where a package’s package manager is declared: in the top-level packageManager field, or in devEngines.packageManager.

The package manager can be declared in two places in a package.json:

packageManager: read by Node.js’ Corepack and supported by essentially every package manager:

{
"packageManager": "pnpm@12.14.0"
}

devEngines.packageManager: read by pnpm, Corepack, and recent versions of npm:

{
"devEngines": {
"packageManager": {
"name": "pnpm",
"version": "12.14.0"
}
}
}

devEngines is the more versatile of the two, and keeps the package manager next to the other development environment requirements, such as devEngines.runtime. Using one form consistently makes it clear which one tools should read.

With Default Options (prefer: “devEngines”)

Section titled “With Default Options (prefer: “devEngines”)”
{
"packageManager": "pnpm@12.14.0"
}
{
"packageManager": "pnpm@12.14.0",
"devEngines": {
"packageManager": {
"name": "pnpm",
"version": "12.14.0"
}
}
}
{
"devEngines": {
"packageManager": {
"name": "pnpm",
"version": "12.14.0"
}
}
}
{
"packageManager": "pnpm@12.14.0",
"devEngines": {
"packageManager": {
"name": "pnpm",
"version": "12.14.0"
}
}
}
Name Description Type Choices Default
prefer Specifies where the package manager should be declared. String devEngines, packageManager devEngines

The prefer option specifies where the package manager should be declared:

  • "devEngines" (default): Disallows the packageManager field in favor of devEngines.packageManager
  • "packageManager": Disallows devEngines.packageManager in favor of the packageManager field
{
"package-json/consistent-package-manager-declaration": [
"error",
{
"prefer": "packageManager"
}
]
}

When the declaration can be moved to the preferred place without losing anything, the rule fixes it automatically. If both places already declare the same package manager and version, the non-preferred one is removed.

Otherwise, the fix is offered as an editor suggestion so you can review it first. This happens when:

  • the packageManager field includes a Corepack integrity hash (e.g. pnpm@12.14.0+sha512.<hash>), which devEngines doesn’t support;
  • devEngines.packageManager includes onFail, which in turn the packageManager field doesn’t support;
  • both places declare a package manager, but they don’t match.

The rule reports without a fix when the declaration can’t be converted, such as when devEngines.packageManager is an array, or specifies a version range rather than an exact version, which the packageManager field doesn’t allow.

If you intentionally declare the package manager in both places (for example, to support tools that only read one of them), you can disable this rule.