Skip to content

changeset publish crashes on already-published packages under npm trusted publishing (OIDC) #2099

Closed

Description

@zachbwh-secure-fresha

Summary

Under npm trusted publishing (OIDC), changeset publish runs with no auth token, because an _authToken in .npmrc makes npm skip its OIDC exchange. With no token, the pre-publish npm info check returns 404 for every private package, so changesets concludes nothing is published and attempts to publish every package, including unchanged ones whose current version is already on the registry. Those return E403, and instead of being skipped the run crashes:

🦋 error TypeError: Cannot read properties of undefined (reading 'includes')
🦋 error     at isAlreadyPublishedError (.../@changesets/cli/dist/changesets-cli.cjs.js:873:17)
🦋 error     at internalPublish (.../@changesets/cli/dist/changesets-cli.cjs.js:957:41)

Root cause

In the --json publish path inside internalPublish:

if (json.error.code === "E403" && isAlreadyPublishedError(json.error.summary)) { ... }
// isAlreadyPublishedError(output) => output.includes("cannot publish over the previously published version")

With pnpm publish --json (and bun), the error JSON has error.code === "E403" but no error.summary, so isAlreadyPublishedError(undefined) throws. npm does populate summary, so npm-based repos don't crash, but they still report the already-published package as failed rather than skipped, because the message ("...previously published versions: x.y.z") isn't always matched where the check looks. The publish tool is chosen by changesets via package-manager-detector, so which behaviour you get depends on the detected package manager rather than anything the user controls.

When this happens

This only shows up with npm trusted publishing, which is still an uncommon setup, so most workflows never reach this path. But for a repo that does use it, the tokenless publish means the npm info precheck can never see private packages, so changesets re-attempts already-published versions on every release. Any release that leaves at least one package unchanged (its version already on npm) will hit the failing E403 path.

Reproduction

  1. pnpm (or bun) workspace with private scoped packages, publishing via npm trusted publishing (OIDC, no token present at publish time).
  2. A release where at least one package is unchanged and its current version is already on npm.
  3. pnpm changeset publish crashes on the first already-published package.

Workaround

For anyone hitting this before it's fixed: we added a step that runs before changeset publish, while a read token is still available. It checks each workspace package's current version against the registry and sets private: true on the ones that are already published. changesets skips private packages, so changeset publish then only attempts the genuinely new versions. The read token is removed again before the publish step, so the actual publish still happens tokenless via OIDC. The package.json edits are made in the CI checkout and never committed. This sidesteps the crash entirely and has the side benefit of not re-attempting every unchanged package on each release.

Proposed fix

Make isAlreadyPublishedError null-safe and have it check all the fields the message might land in across package managers:

function isAlreadyPublishedError(...parts) {
  return parts.filter(Boolean).join("\n").includes("cannot publish over the previously published version");
}
// call: isAlreadyPublishedError(json.error.summary, json.error.detail, stderr.toString())

It would also help to document that trusted publishing leaves the npm info precheck unauthenticated, since the tokenless read is a consequence of the OIDC requirement.

Environment: @changesets/[email protected], npm trusted publishing (OIDC), pnpm 11.6 / bun 1.2.

Activity

  1. cschanhniem commented on Jun 18, 2026

    @cschanhniem

    We hit this exact crash in our CI pipeline. The error.summary being undefined with pnpm/bun publish --json is what makes it so confusing — the error code is E403 but the null-safety check isn't there.

    Your workaround is clever (setting private: true pre-publish), but I want to suggest a simpler approach: if you set the NPM_TOKEN env var to an empty string before changeset publish (rather than having it absent entirely), npm/pnpm with OIDC will still use the tokenless path but changesets' pre-check npm info calls will gracefully 404 with a readable error instead of crashing.

    For the actual fix, I'd also suggest checking stderr output in isAlreadyPublishedError. With pnpm --json, the E403 body sometimes has the "previously published" message in a different field than summary — I've seen it land in error.detail or even in raw stderr depending on the version:

    function isAlreadyPublishedError(...parts) {
      return parts.filter(Boolean).some(p =>
        p.includes('cannot publish over the previously published version')
      );
    }
    // call: isAlreadyPublishedError(json.error.summary, json.error.detail, stderr)

    The broader issue of OIDC + npm info prechecks returning 404 for private packages is harder to fix, but at minimum the crash should be a clean skip.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions