npm / npm/cli

[BUG] argumentless -w argument defaults to true

Open
#6,772 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Priority 2 Release 10.x Release 9.x ws:config
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
Current Behavior

The --workspace/w argument requires an argument, but if provided without an argument, assumes the value "true", and produces confusing output:

npm ls -w

npm ERR! No workspaces found:
npm ERR!   --workspace=true

This makes it sound like npm did not see ANY workspaces, not that the argument was bad.

Additionally, if one workspace is missing, npm provides no warning:

npm -w myworkspace -w missingworkspace ls acts as if -w missingworkspace was not provided. This can be confusing if -w gobbles up other args:

npm -w myworkspace -w run rebuild which treats run as an argument for -w, running npm rebuild without warning.

Expected Behavior
  • The command line parser should say something like "option requires an argument -- -w".
  • The help text should explain what -w expects. e.g: "-w='foo'; 'foo' was not a package name nor a path to a workspace". This should happen even if there is a valid workspace. e.g.
  • The help text should list the present workspaces or tell the user how to list identified workspaces.
Steps To Reproduce
  1. In this environment...
  2. With this config...
  3. Run '...'
  4. See error...
Environment
  • npm:
  • Node.js:
  • OS Name:
  • System Model Name:
  • npm config:
; copy and paste output from `npm config ls` here

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 npm ls -w and the multiple -w examples, then trace the npm CLI argument parsing and workspace validation paths. Check how errors and help text are generated; done means missing or argumentless workspace values are reported explicitly without being ignored, including when another workspace is valid.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
cli, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.