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
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.```

github-actions[bot]
Diff Delta:
0
Classified as:  Bug Fix

github-actions[bot]'s Description of Work #8565 [BUG] npm install --json no longer JSON

Backport of #9823 to release/v11.

0 total changed files
You’ve reached the end
Your attention span may now revert to "default human"