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.
More Details
Section titled “More Details”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.
Examples
Section titled “Examples”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" } }}With prefer: “packageManager”
Section titled “With prefer: “packageManager””{ "devEngines": { "packageManager": { "name": "pnpm", "version": "12.14.0" } }}{ "packageManager": "pnpm@12.14.0", "devEngines": { "packageManager": { "name": "pnpm", "version": "12.14.0" } }}{ "packageManager": "pnpm@12.14.0"}{ "packageManager": "pnpm@12.14.0", "devEngines": { "runtime": { "name": "node", "version": ">=24" } }}Options
Section titled “Options”| Name | Description | Type | Choices | Default |
|---|---|---|---|---|
prefer |
Specifies where the package manager should be declared. | String | devEngines, packageManager |
devEngines |
prefer
Section titled “prefer”The prefer option specifies where the package manager should be declared:
"devEngines"(default): Disallows thepackageManagerfield in favor ofdevEngines.packageManager"packageManager": DisallowsdevEngines.packageManagerin favor of thepackageManagerfield
{ "package-json/consistent-package-manager-declaration": [ "error", { "prefer": "packageManager" } ]}Fixing
Section titled “Fixing”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
packageManagerfield includes a Corepack integrity hash (e.g.pnpm@12.14.0+sha512.<hash>), whichdevEnginesdoesn’t support; devEngines.packageManagerincludesonFail, which in turn thepackageManagerfield 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.
When Not to Use It
Section titled “When Not to Use It”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.
Related Rules
Section titled “Related Rules”require-devEngines- Enforces that thedevEnginesproperty is present.require-packageManager- Enforces that thepackageManagerproperty is present.valid-devEngines- Enforces that thedevEnginesproperty is valid.valid-packageManager- Enforces that thepackageManagerproperty is valid.