Skip to content

fix(ls): null-check edge.to when filtering workspaces - #10188

Open
ump45nose wants to merge 2 commits into
npm:latestfrom
ump45nose:fix/10157-ls-workspaces-false-null-edge
Open

ump45nose wants to merge 2 commits into
npm:latestfrom
ump45nose:fix/10157-ls-workspaces-false-null-edge

Conversation

@ump45nose

Copy link
Copy Markdown
Contributor

Fixes

Fixes #10157

npm ls --workspaces=false crashed with Cannot read properties of null (reading 'isWorkspace') whenever a root dependency was missing or omitted. The workspaces filter read edge.to.isWorkspace without checking that edge.to exists (unmet deps use a null target).

Changes

  • Guard edge.to before isWorkspace in filterBySelectedWorkspaces.
  • Regression test: workspace tree with an unmet root prod dep + --workspaces=false rejects with ELSPROBLEMS instead of TypeError.

Test plan

  • tap test/lib/commands/ls.js --grep 'issue 10157' --no-coverage
  • Manual: workspace fixture with missing root dep → npm ls --workspaces=false --depth=0 exits ELSPROBLEMS, no TypeError

AI disclosure

Prepared with AI assistance (Grok Bot). Changes and tests reviewed before submit.

`--workspaces=false` walked root edges and read `edge.to.isWorkspace`
without guarding a missing dependency (`edge.to === null`), which threw
TypeError. Skip only when the edge actually resolves to a workspace.

Fixes npm#10157
@ump45nose
ump45nose requested a review from a team as a code owner October 29, 2026 05:29
CI eslint no-multiple-empty-lines failed on the --no-workspaces
regression test block.
@ump45nose

Copy link
Copy Markdown
Contributor Author

CI Lint failed on test/lib/commands/ls.js (no-multiple-empty-lines — an extra blank line after the --no-workspaces regression case).

Pushed a one-line follow-up that removes the duplicate blank. Tests were already green; this is lint-only.

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.

[BUG] npm ls --workspaces=false crashes with an uninstalled root dependency

2 participants