Skip to content

pnpm 12 regression: catalogMode in prefer/strict ignores the catalog for pnpm add <pkg> when no version is specified (writes a direct range instead) #14865

Description

@levisantosp

Verify latest release

  • I verified that the issue exists in the latest pnpm release

pnpm version

12.4.1

Which area(s) of pnpm are affected? (leave empty if unsure)

Dependencies resolver

Link to the code that reproduces this issue or a replay of the bug

No response

Reproduction steps

  1. Run pn init to create the package.json

  2. Create a pnpm-workspace.yaml in the project root with:

    catalogMode: prefer # or strict
    catalog:
      tailwindcss: ^4.3.3
  3. Run:

    pn add -D tailwindcss
  4. Observe the warning/error and what gets written to package.json.

Describe the Bug

When a package is already defined in the default catalog and its catalog range covers the version pn add wants to install, pn add <pkg> (without an explicit version) does not use the catalog. Instead it warns and writes a direct version range:

[WARN] Catalog version mismatch for "tailwindcss": using direct version "^4.3.3" instead of catalog version "^4.3.3".

devDependencies:
+ tailwindcss 4.3.3

package.json after the command:

{
  "devDependencies": {
    "tailwindcss": "^4.3.3"
  }
}

With catalogMode: strict the same command fails outright:

Error: ERR_PNPM_CATALOG_VERSION_MISMATCH
  × adding a new package
  ╰─▶ Wanted dependency outside the version range defined in catalog

Note the two specifiers in the warning are identical (^4.3.3 vs ^4.3.3), so there is no real mismatch — the catalog does cover the wanted version and the dependency should resolve through the catalog.

Passing an explicit exact version works as expected:

pn add -D tailwindcss@4.3.3   # -> "tailwindcss": "catalog:"  ✅

Regression

This works in v11 and regressed in v12:

pnpm version pn add tailwindcss result
11.27.0 "tailwindcss": "catalog:", no warning/error
12.0.0 "tailwindcss": "^4.3.3" + warning/error
12.1.0 "tailwindcss": "^4.3.3" + warning/error
12.2.1 "tailwindcss": "^4.3.3" + warning/error
12.3.4 "tailwindcss": "^4.3.3" + warning/error
12.4.1 "tailwindcss": "^4.3.3" + warning/error

This is related to but distinct from #13715 (catalogMode: strict rejecting pn update <pkg>@<version> against a range-pinned entry), which fixed the case where an exact version is supplied. The plain pn add <pkg> case (a wanted range) is still not covered.

Expected Behavior

When the default catalog defines tailwindcss: ^4.3.3:

  • pn add -D tailwindcss should add "tailwindcss": "catalog:" to package.json (the catalog range covers the wanted range), with no warning.
  • catalogMode: strict should not throw ERR_PNPM_CATALOG_VERSION_MISMATCH, because the wanted version is inside the catalog's range.
  • catalogMode: prefer should fall back to a direct version only when the catalog genuinely cannot satisfy the wanted version.
  • Behavior should match v11 (11.27.0), which already does the right thing.

Which Node.js version are you using?

24.19

Which operating systems have you used?

  • macOS
  • Windows
  • Linux

If your OS is a Linux based, which one it is? (Include the version if relevant)

7.2.3-1-cachyos

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions