npm / npm/cli

[BUG] workspace scripts do not propagate exit codes

Open
#6,506 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Needs Triage Release 9.x
Dominant language
JavaScript
Stars
10.1k
Forks
4.7k
Avg merge
2d 2h
Merged PRs (30d)
19

Description

Is there an existing issue for this?
  • I have searched the existing issues
This issue exists in the latest npm version
  • I am using the latest npm
Minimal Setup

package.json

{
  "workspaces": ["child"],
  "scripts": {
    "exit-100": "exit 100"
  }
}

child/package.json

{
  "scripts": {
    "exit-100": "exit 100"
  }
}
Repro Steps

Behavior in root:

npm run exit-100
echo $? # correctly returns 100

Behavior in workspace:

npm run exit-100 --workspace child
echo $? # incorrectly returns 1

# OR

cd child
npm run exit-100
echo $? # incorrectly returns 1

Also note, if you amend the root package.json to remove the workspaces and then repeat those final steps:

cd child
npm run exit-100
echo $? # (now without workspaces config in the level above) correctly returns 100
Environment
  • npm: 9.5.0
  • Node.js: 18.15.0
  • OS Name: macOS 13.3.1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the workspace commands from the issue with npm 9.5.0 and Node.js 18.15.0, comparing root and child execution. Trace the workspace script execution and exit-status handling in the npm CLI entry points. Done means a child script exiting with 100 propagates exit code 100 both from the workspace flag and from the child directory.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
cli, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.