Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] npm list --json produces invalid json when --silent is included #2163

Closed
csvan opened this issue Nov 12, 2020 · 3 comments
Closed

[BUG] npm list --json produces invalid json when --silent is included #2163

csvan opened this issue Nov 12, 2020 · 3 comments
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 7.x work is associated with a specific npm 7 release

Comments

@csvan
Copy link

csvan commented Nov 12, 2020

Current Behavior:

In a situation where an error occurs but is suppressed by the --silent flag when running npm list --json, the resulting json output is invalid.

For example, the resulting json can look like this:

{
  "version": "0.0.0",
  "name": "@myscope/mypackage",
  "problems": [],
  "dependencies": {}
}
{
  "error": {
    "code": "ELSPROBLEMS",
    "summary": "invalid: @pm2/pm2-version-check@1.0.3 /pathtoproject/node_modules/@pm2/pm2-version-check\nmissing: react-dom@>= 16.8.0, required by styled-components@5.2.1\nmissing: react@>= 16.8.0, required by styled-components@5.2.1\nmissing: ts-node@>=9.0.0, required by jest-config@26.6.3\nmissing: bufferutil@^4.0.1, required by ws@7.2.5\nmissing: utf-8-validate@^5.0.2, required by ws@7.2.5\nmissing: bufferutil@^4.0.1, required by ws@7.3.1\nmissing: utf-8-validate@^5.0.2, required by ws@7.3.1\nmissing: canvas@^2.5.0, required by jsdom@16.4.0",
    "detail": ""
  }
}

These are two json objects in succession without a valid separator, trying to run e.g. JSON.parse() on it will fail since it is invalid.

Expected Behavior:

The resulting output should only contain the result of npm list --json, and that result should be valid json.

Steps To Reproduce:

Environment:

  • OS: OSX Catalina
  • Node: 15.0.0
  • npm: 7.0.0

Note that this most likely applies to npm 6 as well.

@csvan csvan added Bug thing that needs fixing Needs Triage needs review for next steps Release 7.x work is associated with a specific npm 7 release labels Nov 12, 2020
@ljharb
Copy link
Contributor

ljharb commented Nov 12, 2020

What happens if you, in turn, redirect stdout and then stderr to /dev/null?

@csvan
Copy link
Author

csvan commented Nov 13, 2020

This seems to be the same issue as #2150, which was closed just now. Will see if I can still reproduce after that.

@csvan
Copy link
Author

csvan commented Nov 14, 2020

Fixed in npm 7.0.11, where the err content will now be printed to console whereas stdout will correctly end up in the piped file.

@csvan csvan closed this as completed Nov 14, 2020
@darcyclarke darcyclarke added this to the OSS - Sprint 19 milestone Nov 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 7.x work is associated with a specific npm 7 release
Projects
None yet
Development

No branches or pull requests

3 participants