Skip to content

syncEnvLockfile skipped when running via corepack, leaving packageManagerDependencies stale #11397

@tim-gq

Description

@tim-gq

First, thanks for the incredibly quick turnaround on #11387 — shipping the fix in 11.0.1 the same day was impressive!

Description

The fix in #11392 for syncing stale packageManagerDependencies entries works correctly, but is bypassed when pnpm is executed via corepack. Since devEngines.packageManager typically implies corepack usage, the fix is effectively unreachable for the primary use case.

Root Cause

In pnpm/src/main.ts, the package manager handling block (including syncEnvLockfile) is wrapped in:

if (!isExecutedByCorepack() && cmd !== 'setup' && ...) {
  // ...
  checkPackageManager(pm)
  await syncEnvLockfile(config, context)
}

When corepack invokes pnpm, COREPACK_ROOT is set, causing isExecutedByCorepack() to return true and skip the entire block.

Steps to Reproduce

  1. Use devEngines.packageManager in package.json:

    {
      "devEngines": {
        "packageManager": {
          "name": "pnpm",
          "version": "11.0.1"
        }
      }
    }
  2. Have a stale lockfile with old version in packageManagerDependencies:

    packageManagerDependencies:
      pnpm:
        specifier: 11.0.0-rc.5
        version: 11.0.0-rc.5
  3. Run pnpm install (which goes through corepack due to devEngines)

  4. Observe that packageManagerDependencies remains at rc.5 despite running pnpm 11.0.1

Expected Behavior

The packageManagerDependencies section should be updated to 11.0.1, matching the running pnpm version.

Actual Behavior

The stale rc.5 entry persists because syncEnvLockfile is never called when COREPACK_ROOT is set.

The Gap

  • Corepack: Manages which pnpm version runs, but doesn't touch the lockfile
  • pnpm: Has code to update the lockfile (syncEnvLockfile), but skips it when corepack is involved

This creates a situation where neither tool updates the packageManagerDependencies section.

Suggested Fix

Consider running syncEnvLockfile even when executed by corepack, at least for the case where devEngines.packageManager is declared. The lockfile integrity record is still valuable even when corepack handles version selection.

Environment

  • pnpm version: 11.0.1
  • Node.js version: 24.x
  • corepack version: (bundled with Node)
  • OS: macOS

Related

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions