Skip to content

Fixed handling of the npm 12 info output - #2159

Merged
Andarist merged 3 commits into
changesets:maintenance/v2from
ingvaldlorentzen:fix/npm-12-info
Jul 15, 2026
Merged

Fixed handling of the npm 12 info output#2159
Andarist merged 3 commits into
changesets:maintenance/v2from
ingvaldlorentzen:fix/npm-12-info

Conversation

@ingvaldlorentzen

@ingvaldlorentzen ingvaldlorentzen commented Jul 13, 2026

Copy link
Copy Markdown

In npm v12 npm view/npm info always return an array.

This causes changesets to incorrectly interpret the packages as not published, and attempt to publish them, causing errors from the registry.
e.g.
image

This PR fixes this by detecting if the output is an array, and grabbing the last element if it is. This should keep compatibility with v11 and v12 behaviour.

The "error" state is also changed, so it now detects if empty string and E404.

@changeset-bot

changeset-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 149fd91

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@changesets/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.86%. Comparing base (9f2cb2a) to head (149fd91).

Additional details and impacted files
@@                Coverage Diff                 @@
##           maintenance/v2    #2159      +/-   ##
==================================================
+ Coverage           83.85%   83.86%   +0.01%     
==================================================
  Files                  56       56              
  Lines                2465     2467       +2     
  Branches              743      744       +1     
==================================================
+ Hits                 2067     2069       +2     
  Misses                392      392              
  Partials                6        6              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Andarist

Copy link
Copy Markdown
Member

This is already being fixed in #2097 but that's in the works and targets the upcoming (soon!) v3 release.

Given this is a pretty big break for npm users, we can definitely accept a PR targeting v2 - but that should be opened against the maintenance/v2 branch.

Comment thread packages/cli/src/commands/publish/npm-utils.ts Outdated
@ingvaldlorentzen
ingvaldlorentzen changed the base branch from main to maintenance/v2 July 13, 2026 15:03
@ingvaldlorentzen
ingvaldlorentzen changed the base branch from maintenance/v2 to main July 13, 2026 15:04
@ingvaldlorentzen
ingvaldlorentzen changed the base branch from main to maintenance/v2 July 13, 2026 15:21
@ingvaldlorentzen

Copy link
Copy Markdown
Author

This is already being fixed in #2097 but that's in the works and targets the upcoming (soon!) v3 release.

Awesome! Looking forward to check out v3!

Given this is a pretty big break for npm users, we can definitely accept a PR targeting v2 - but that should be opened against the maintenance/v2 branch.

I've retargeted this PR to be based on and point towards maintenance/v2 now!

quazardous added a commit to quazardous/qdadm that referenced this pull request Jul 15, 2026
… detection

npm v12's `npm info --json` always returns an array, which
@changesets/cli 2.31.0 misparses as 'never published': it re-attempts
every already-published version, the registry refuses (cannot publish
over previously published), and the publish step exits 1 on every
train (first seen on the 2.7.0 release, reproduced on rerun; the
publishes themselves succeeded — the red came from the re-attempts).

The workflow installed npm@latest, which moved from 11.x to 12.x
between the 2.6.1 (green) and 2.7.0 (red) trains. Pin the 11.x line
(OIDC Trusted Publishing needs >= 11.5.1); restore @latest once
changesets/changesets#2159 ships.
Comment on lines +168 to +169
// npm 12 emits an E404 error instead of empty stdout when nothing
// matches `latest` (e.g. GitHub Packages without a `latest` dist-tag)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh, I can't reproduce this - and the npm's source code seems to back that up:
https://github.com/npm/cli/blob/7b1f6c173d17b3bf30e45426f6df39473c6a1163/lib/commands/view.js#L189-L196

note: calling npm info pkg-a is like npm info pkg-a@latest, so even if that returns no matches, it still shouldn't return E404

Am I missing something? How have you observed this?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, you're right, I goofed.
Had been testing against some actual versions when debuggin, and made an incorrect assumption, sorry about that.
Just pushed a commit that removes this code and the related test, makes the PR quite a bit simpler, thanks for the feedback!

@Andarist Andarist changed the title fix: npm v12 info json array Fixed handling of the npm 12 info output Jul 15, 2026
@Andarist
Andarist added this pull request to the merge queue Jul 15, 2026
Merged via the queue into changesets:maintenance/v2 with commit 15cf592 Jul 15, 2026
9 checks passed
ku5ic added a commit to ku5ic/foxhole that referenced this pull request Jul 17, 2026
…24)

## Summary
- Root cause of today's recurring Release failures ("You cannot publish
over the previously published versions: 1.0.5"): npm 12 (installed by
the Release job's OIDC npm-upgrade step) changed `npm info --json` to
wrap its output in an array. `@changesets/cli@2.31.0`'s
`getPackageInfo()` reads `pkgInfo.versions` off the unwrapped result, so
under npm 12 it's always `undefined`, and `changeset publish` concludes
every already-published package is unpublished, then re-attempts
publishing it. npm correctly rejects the duplicate, and Release goes
red.
- This is a genuine upstream defect, not a misuse on our side: confirmed
via `changesets/changesets#2164` (closed), matching our exact symptom
and environment (npm 12.0.1, `@changesets/cli@2.31.0`, GitHub Actions).
Fixed by `changesets/changesets#2159`, released in
`@changesets/cli@2.31.1`.
- Bumped the lockfile to `2.31.1` (already permitted by the existing
`^2.31.0` range in package.json, no manifest change needed). Verified
the array-unwrap fix (`Array.isArray(parsed) ? parsed[0] : parsed`) is
present in the installed source.

## Why this wasn't caught by the earlier fixes today
- #21 (removing the release job's npm cache) and #22 (the audit-fix PR)
both happened to pass Release, but for unrelated reasons: #22's run took
`changesets/action`'s "open a Version Packages PR" path (since it
carried a pending changeset) rather than the "attempt to publish" path
that triggers this bug. The defect was still live underneath.

## Verification
- `run-checks.sh`: 4 passed, 0 failed, 0 skipped (typecheck, lint,
format, test).

## Sequencing
This should merge **before** #23 (the pending Version Packages PR), so
the eventual patch-release publish run uses the fixed `@changesets/cli`,
and so ordinary future pushes to main don't hit this bug again.
rexxars added a commit to sanity-io/get-it that referenced this pull request Jul 30, 2026
Fixes the failing Release workflow on main: npm 12 (now npm@latest in the
shared changesets workflow) wraps successful `npm info --json` output in
an array, which made changeset publish treat 9.4.0 as unpublished and
fail attempting to republish it. Fixed upstream in
changesets/changesets#2159 (released in 2.31.1).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants