-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[BUG] --json outputs errors to stdout instead of stderr #2150
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
Milestone
Comments
raineorshine
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 9, 2020
isaacs
added a commit
that referenced
this issue
Nov 11, 2020
darcyclarke
pushed a commit
that referenced
this issue
Nov 13, 2020
Fixes: #2150 Credit: @isaacs Close: #2155 Reviewed-by: @ruyadorno
lukekarrys
added a commit
that referenced
this issue
Oct 19, 2022
This also adds a new output method `outputBuffer()` which will buffer all output until it is flushed in the exit handler. This allows the exit handler to catch any errors and append them to the output when in json mode. This was necessary to not introduce a regression in the case of #2150. BREAKING CHANGE: `npm` now outputs some json errors on stdout. Previously `npm` would output all json formatted errors on stderr, making it difficult to parse as the stderr stream usually has logs already written to it. In the future, `npm` will differentiate between errors and crashes. Errors, such as `E404` and `ERESOLVE`, will be handled and will continue to be output on stdout. In the case of a crash, `npm` will log the error as usual but will not attempt to display it as json, even in `--json` mode. Moving a case from the category of an error to a crash will not be considered a breaking change. For more information see npm/rfcs#482. Closes #2740 Closes npm/statusboard#589
lukekarrys
added a commit
that referenced
this issue
Oct 19, 2022
This also adds a new output method `outputBuffer()` which will buffer all output until it is flushed in the exit handler. This allows the exit handler to catch any errors and append them to the output when in json mode. This was necessary to not introduce a regression in the case of #2150. BREAKING CHANGE: `npm` now outputs some json errors on stdout. Previously `npm` would output all json formatted errors on stderr, making it difficult to parse as the stderr stream usually has logs already written to it. In the future, `npm` will differentiate between errors and crashes. Errors, such as `E404` and `ERESOLVE`, will be handled and will continue to be output on stdout. In the case of a crash, `npm` will log the error as usual but will not attempt to display it as json, even in `--json` mode. Moving a case from the category of an error to a crash will not be considered a breaking change. For more information see npm/rfcs#482. Closes #2740 Closes npm/statusboard#589
lukekarrys
added a commit
that referenced
this issue
Oct 19, 2022
This also adds a new output method `outputBuffer()` which will buffer all output until it is flushed in the exit handler. This allows the exit handler to catch any errors and append them to the output when in json mode. This was necessary to not introduce a regression in the case of #2150. BREAKING CHANGE: `npm` now outputs some json errors on stdout. Previously `npm` would output all json formatted errors on stderr, making it difficult to parse as the stderr stream usually has logs already written to it. In the future, `npm` will differentiate between errors and crashes. Errors, such as `E404` and `ERESOLVE`, will be handled and will continue to be output on stdout. In the case of a crash, `npm` will log the error as usual but will not attempt to display it as json, even in `--json` mode. Moving a case from the category of an error to a crash will not be considered a breaking change. For more information see npm/rfcs#482. Closes #2740 Closes npm/statusboard#589
lukekarrys
added a commit
that referenced
this issue
Oct 19, 2022
This also adds a new output method `outputBuffer()` which will buffer all output until it is flushed in the exit handler. This allows the exit handler to catch any errors and append them to the output when in json mode. This was necessary to not introduce a regression in the case of #2150. BREAKING CHANGE: `npm` now outputs some json errors on stdout. Previously `npm` would output all json formatted errors on stderr, making it difficult to parse as the stderr stream usually has logs already written to it. In the future, `npm` will differentiate between errors and crashes. Errors, such as `E404` and `ERESOLVE`, will be handled and will continue to be output on stdout. In the case of a crash, `npm` will log the error as usual but will not attempt to display it as json, even in `--json` mode. Moving a case from the category of an error to a crash will not be considered a breaking change. For more information see npm/rfcs#482. Closes #2740 Closes npm/statusboard#589
lukekarrys
added a commit
that referenced
this issue
Oct 19, 2022
This also adds a new output method `outputBuffer()` which will buffer all output until it is flushed in the exit handler. This allows the exit handler to catch any errors and append them to the output when in json mode. This was necessary to not introduce a regression in the case of #2150. BREAKING CHANGE: `npm` now outputs some json errors on stdout. Previously `npm` would output all json formatted errors on stderr, making it difficult to parse as the stderr stream usually has logs already written to it. In the future, `npm` will differentiate between errors and crashes. Errors, such as `E404` and `ERESOLVE`, will be handled and will continue to be output on stdout. In the case of a crash, `npm` will log the error as usual but will not attempt to display it as json, even in `--json` mode. Moving a case from the category of an error to a crash will not be considered a breaking change. For more information see npm/rfcs#482. Closes #2740 Closes npm/statusboard#589
# for free
to join this conversation on GitHub.
Already have an account?
# 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
Current Behavior:
Running
npm ls --json
with missing dependencies outputs the error tostdout
instead ofstderr
. 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 tostderr
.i.e.
stdout
:stderr
: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:
2>/dev/null
makes it clear that the following output is all onstdout
:Environment:
OS: 10.14.6
Node: 15.1.0
npm: 7.0.9
The text was updated successfully, but these errors were encountered: