Description
The problem
NPM's --json option allows scripts to invoke an NPM command and receive machine-readable JSON that can be easily processed. In previous NPM versions, the JSON was written to STDOUT and all other messages were written to STDERR, making it easy for a script to extract the JSON.
With NPM 7.x, everything is mixed together on STDERR. This defeats the point of the --json
feature, which was to make parsing easy. Instead, a script has to implement heuristics to guess which STDERR lines are JSON or not. Scripts developed for NPM 6 now fail because they are reading the wrong stream.
Steps To Reproduce:
-
Correct behavior: With NPM 6.x, invoke this command:
npm search --json
The JSON output is written to STDOUT:
{ "error": { "code": null, "summary": "search must be called with arguments", "detail": "" } }
The console messages are written to STDERR:
npm ERR! search must be called with arguments npm ERR! A complete log of this run can be found in:
-
Broken behavior: With NPM 7.5.4 (the latest version), invoke the same command. Both outputs are mixed together on STDERR. Nothing is written to STDOUT.
This regression appears to have been introduced with NPM 7.0.0.
Environment:
- OS: All OS's
- Node: 12.17.0
- npm: 7.5.4