fix: keep dry-run output valid json #9928

Merged
github-actions[bot] opened 5:21pm on August 27, 2026 wanted to merge 1 commit into npm/cli release/v11 from
backport/v11/9823

Pull Request Overview

  • Opened on August 27, 2026
  • Status Merged
  • Commit count 1 with first commit August 25, 2026

Total Delta

0 Total Diff Delta

Open Days

Open 17 weekdays

Test Delta

0 Diff Delta in Test Files
Breakdown by Phase

How long has this pull request spent in each phase of its lifecycle?

Fraction of total time Business days Phase
N/A 247.0 days Issue creation to work beginning
 
2.0 days Authoring 1 commit before pull request opened for review
 
0.3 days Awaiting first review
 
0.4 days Revising work with 0 commits in response to 1 review that left 0 comments
 
15.0 days Merge to deploy (still awaiting deployment)

Total time for pull request 2.7 business days from first commit authored to merge
Still awaiting deployment

Author avatar

fix: keep dry-run output valid json

Backport of #9823 to release/v11.

This work implements [BUG] npm install --json no longer JSON (closed)

Is there an existing issue for this?

  • [x] I have searched the existing issues

This issue exists in the latest npm version

  • [x] I am using the latest npm

Current Behavior

npm install --dry-run --json does not return json

Expected Behavior

npm install --dry-run --json returns valid json

Steps To Reproduce

  1. In unix/macos
mkdir test
cd test
npm init -y
npm install --save debug
rm -rf node_modules/debug
npm install --dry-run --json

output is

add debug 4.4.3
{
  "add": [
    {
      "name": "debug",
      "version": "4.4.3",
      "path": "/Users/gregg/temp/delme/npm-json/node_modules/debug"
    }
  ],
  "added": 1,
  "audited": 0,
  "change": [],
  "changed": 0,
  "funding": 0,
  "remove": [],
  "removed": 0
}

That first line is not JSON which means any tool using --json breaks

This apparently broke in v10.4.0, v10.3.0 doesn't have the issue

Environment

  • npm: 11.6.0
  • Node.js:
  • OS Name: MacOS
  • System Model Name: 15.6.1
  • npm config: ```ini ; "user" config from /Users/gregg/.npmrc

//registry.npmjs.org/:_authToken = (protected)

; "env" config from environment

fund = false

; node bin location = /Users/gregg/.nvm/versions/node/v24.8.0/bin/node ; node version = v24.8.0 ; npm local prefix = /Users/gregg/src ; npm version = 11.6.0 ; cwd = /Users/gregg/src ; HOME = /Users/gregg ; Run npm config ls -l to show all defaults.```

PR was closed without comments.