cli icon indicating copy to clipboard operation
cli copied to clipboard

[BUG] npm install --json no longer JSON

Open greggman opened this issue 3 months ago • 0 comments

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:
; "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.```

greggman avatar Sep 14 '25 14:09 greggman