Skip to content

[BUG] --json outputs errors to stdout instead of stderr #2150

Closed

Description

@raineorshine

Current Behavior:

Running npm ls --json with missing dependencies outputs the error to stdout instead of stderr. This creates two top-level JSON objects, making it unparseable.

This is a regression from v6.

May be related to: #1109

Expected Behavior:

Normal output should print to stdout, errors should print to stderr.

i.e.

stdout:

{
  "name": "temp",
  "problems": [
    "missing: foo@1.0.0, required by temp@"
  ],
  "dependencies": {
    "foo": {
      "required": "1.0.0",
      "missing": true,
      "problems": [
        "missing: foo@1.0.0, required by temp@"
      ]
    }
  }
}

stderr:

{
  "error": {
    "code": "ELSPROBLEMS",
    "summary": "missing: foo@1.0.0, required by temp@",
    "detail": ""
  }
}

Steps To Reproduce:

For the life of me I can't figure out why this test passes, as it clearly asserts the expected stdout.

That said, I can reproduce the issue running the cli manually on a simple package.json:

$ mkdir issue-2150 && cd issue-2150
$ echo '{ "dependencies": { "foo": "1.0.0" } }' > package.json
$ npm ls --json 2>/dev/null

2>/dev/null makes it clear that the following output is all on stdout:

{
  "name": "temp",
  "problems": [
    "missing: foo@1.0.0, required by temp@"
  ],
  "dependencies": {
    "foo": {
      "required": "1.0.0",
      "missing": true,
      "problems": [
        "missing: foo@1.0.0, required by temp@"
      ]
    }
  }
}
{
  "error": {
    "code": "ELSPROBLEMS",
    "summary": "missing: foo@1.0.0, required by temp@",
    "detail": ""
  }
}

Environment:

OS: 10.14.6
Node: 15.1.0
npm: 7.0.9

Activity

  1. added
    Bug
    Needs Triage
    Release 7.x
    on Nov 9, 2020
  2. added a commit that references this issue on Nov 11, 2020
    f0700d9
  3. added a commit that references this issue on Nov 13, 2020
    6d8d3cc
  4. added a commit that references this issue on Nov 13, 2020
    1dbf0f9
  5. added this to the OSS - Sprint 19 milestone on Nov 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNeeds TriageRelease 7.x

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions