Skip to content

[BUG] npm install --json no longer JSON #8565

@greggman

Description

@greggman

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingNeeds Triageneeds review for next steps

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions