Skip to content

Publishing packages fails if using bun and the npm executable is not available in the environment #32126

@binsky08

Description

@binsky08

Current Behavior

I want to build and publish a nx lib to my GitLab registry while being in my GitLab ci, using bun (v1.2.19) as package manager with the oven/bun:1.2.19 image.

Unfortunately somewhere seems to be a npm view command hard-coded. The bun replacement would be bun info.

Since I'm using the bun container image, there's no npm executable:

bunx --bun nx release publish --verbose
 NX   Running target nx-release-publish for project @myScope/my-cool-lib-name:
- @myScope/my-cool-lib-name
> nx run @myScope/my-cool-lib-name:nx-release-publish
Something unexpected went wrong when checking for existing dist-tags.
 108 |      * perform the npm view step, and just show npm/pnpm publish's dry-run output.
109 |      */
110 |     if (!isDryRun && !options.firstRelease) {
111 |         const currentVersion = packageJson.version;
112 |         try {
113 |             const result = (0, child_process_1.execSync)(npmViewCommandSegments.join(' '), {
                                                     ^
error: Command failed: npm view @myScope/my-cool-lib-name versions dist-tags --json --"@myScope:registry=undefined"
/bin/sh: 1: npm: not found
 signal: null,
 status: 127,
 output: [ null,
  "", "/bin/sh: 1: npm: not found\n"
],
    pid: 395,
 stdout: "",
 stderr: "/bin/sh: 1: npm: not found\n",
      at genericNodeError (node:child_process:959:13)
      at checkExecSyncError (node:child_process:458:27)
      at execSync (node:child_process:278:31)
      at runExecutor (/builds/binsky/my-cool-repo-name/node_modules/@nx/js/src/executors/release-publish/release-publish.impl.js:113:48)
 NX   Running target nx-release-publish for project @myScope/my-cool-lib-name failed
Failed tasks:
- @myScope/my-cool-lib-name:nx-release-publish
Cleaning up project directory and file based variables 00:00
ERROR: Job failed: exit code 1

Expected Behavior

I would like to have support for different package managers when using the nx release publish command. Or at least a way to inject a custom command to replace npm view.

GitHub Repo

https://github.com/binsky08/nx-bun-test-repo

Steps to Reproduce

  1. docker run --rm -it oven/bun:1.2.19 bash
  2. run all following commands within the container (to definitely not having npm installed)
  3. apt update && apt -y install git
  4. git clone https://github.com/binsky08/nx-bun-test-repo
  5. cd nx-bun-test-repo/
  6. bun install
  7. bunx nx release publish --verbose

Since we do not really want to publish this test repo, we would be happy with getting something like 404 Not Found: https://registry.npmjs.org/mylib which indicated a successful registry check.
Instead we get the attached failure logs, because npm is (correctly) not installed.

Nx Report

NX   Report complete - copy this into the issue template

Node           : 24.3.0
OS             : linux-x64
Native Target  : x86_64-linux
bun            : 1.2.19

nx             : 21.3.9
@nx/js         : 21.3.9
@nx/workspace  : 21.3.9
@nx/devkit     : 21.3.9
typescript     : 5.8.3
---------------------------------------
Cache Usage: 0.00 B / 89.63 GB

Failure Logs

# bunx nx release publish --verbose

 NX   Running target nx-release-publish for project mylib:

- mylib

————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

> nx run mylib:nx-release-publish

Something unexpected went wrong when checking for existing dist-tags.
 108 |      * perform the npm view step, and just show npm/pnpm publish's dry-run output.
109 |      */
110 |     if (!isDryRun && !options.firstRelease) {
111 |         const currentVersion = packageJson.version;
112 |         try {
113 |             const result = (0, child_process_1.execSync)(npmViewCommandSegments.join(' '), {
                                                     ^
error: Command failed: npm view mylib versions dist-tags --json --"registry=undefined"
/bin/sh: 1: npm: not found

 signal: null,
 status: 127,
 output: [ null,
  "", "/bin/sh: 1: npm: not found\n"
],
    pid: 5819,
 stdout: "",
 stderr: "/bin/sh: 1: npm: not found\n",

      at genericNodeError (node:child_process:959:13)
      at checkExecSyncError (node:child_process:458:27)
      at execSync (node:child_process:278:31)
      at runExecutor (/home/bun/app/nx-bun-test-repo/node_modules/@nx/js/src/executors/release-publish/release-publish.impl.js:113:48)


————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

 NX   Running target nx-release-publish for project mylib failed

Failed tasks:

- mylib:nx-release-publish

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

No response

Metadata

Metadata

Assignees

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions