Skip to content

fix(js): handle empty npm view output in release-publish executor - #36397

Merged
jaysoo merged 2 commits into
nrwl:masterfrom
gaurav0107:fix/36358-nx-release-publish-fails-when-package-ex
Sep 15, 2026
Merged

jaysoo merged 2 commits into
nrwl:masterfrom
gaurav0107:fix/36358-nx-release-publish-fails-when-package-ex

Conversation

@gaurav0107

Copy link
Copy Markdown
Contributor

Current Behavior

nx release publish (the @nx/js release-publish executor) runs npm view <pkg> versions dist-tags --json to check for existing dist-tags before publishing. Some registries — notably GitHub Packages — return empty stdout with a zero exit code when the package exists but has no published versions/dist-tags yet.

In that case JSON.parse('') throws SyntaxError: Unexpected end of JSON input. Because the resulting SyntaxError carries no stdout/stderr, it falls through the E404/404 guards in the surrounding catch block and is surfaced as:

Something unexpected went wrong when checking for existing dist-tags.
 SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at runExecutor (.../@nx/js/src/executors/release-publish/release-publish.impl.js)

The publish then aborts, making it impossible to (re)publish a package that exists but has no latest tag yet (e.g. a pre-release that only has a next dist-tag).

Expected Behavior

Empty npm view output is treated the same as the package not existing yet: the dist-tag lookup is skipped and publishing continues, so pre-release / first-time publishes to registries that return empty output succeed.

The JSON.parse is guarded with an empty-output check (result.toString().trim() → fall back to {}). A regression test mocks npm view returning empty stdout and asserts the executor proceeds to publish (three execSync calls: npm --version, npm view, publish) instead of reporting the spurious "Something unexpected went wrong when checking for existing dist-tags" failure.

Related Issue(s)

Fixes #36358

@netlify

netlify Bot commented Jul 17, 2026

Copy link
Copy Markdown

👷 Deploy request for nx-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 4332b91

@netlify

netlify Bot commented Jul 17, 2026

Copy link
Copy Markdown

👷 Deploy request for nx-dev pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 4332b91

@jaysoo jaysoo self-assigned this Aug 28, 2026
@jaysoo
jaysoo marked this pull request as ready for review September 15, 2026 17:55
@jaysoo
jaysoo requested a review from a team as a code owner September 15, 2026 17:55
@jaysoo
jaysoo requested a review from lourw September 15, 2026 17:55
The release-publish executor runs
`npm view <pkg> versions dist-tags --json` to check for existing
dist-tags before publishing. Some registries (e.g. GitHub Packages)
return empty stdout with a zero exit code when the package exists but
has no published versions/dist-tags yet.

In that case `JSON.parse('')` threw "Unexpected end of JSON input".
Because the resulting SyntaxError carries no stdout/stderr, it fell
through the E404/404 guards in the catch block and was surfaced as
"Something unexpected went wrong when checking for existing dist-tags",
aborting the publish.

Treat empty view output the same as the package not existing yet: skip
the dist-tag lookup and continue to the publish step. Adds a regression
test covering the empty-output case.
@jaysoo
jaysoo force-pushed the fix/36358-nx-release-publish-fails-when-package-ex branch from 90812c5 to 4876bb3 Compare September 15, 2026 17:55
@nx-cloud

nx-cloud Bot commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

View your CI Pipeline Execution ↗ for commit 4332b91

Command Status Duration Result
nx affected --targets=lint,oxlint,test,build,e2... ✅ Succeeded 5m 44s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 4s View ↗
nx-cloud record -- pnpm nx-cloud conformance:check ✅ Succeeded 1m 3s View ↗
nx build workspace-plugin ✅ Succeeded <1s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded 20s View ↗
nx-cloud record -- nx format:check ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2026-09-15 19:59:03 UTC

@jaysoo
jaysoo enabled auto-merge (squash) September 15, 2026 18:03

@nx-cloud nx-cloud Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nx Cloud has identified a flaky task in your failed CI:

Since the failure was identified as flaky, the solution is to rerun CI. Because this branch comes from a fork, it is not possible for us to push directly, but you can rerun by pushing an empty commit:

git commit --allow-empty -m "chore: trigger rerun"
git push

Nx Cloud View detailed reasoning in Nx Cloud ↗

🔔 Heads up, your workspace has pending recommendations ↗ to auto-apply fixes for similar failures.


🎓 Learn more about Self-Healing CI on nx.dev

@jaysoo
jaysoo merged commit 3a3686f into nrwl:master Sep 15, 2026
19 of 21 checks passed
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.

nx release publish fails when package exists but no latest tag is pushed yet

2 participants