<h3 dir="auto">Current Behavior:</h3>
<p dir="auto">Running <code class="notranslate">npm view --json sompackage dist-tags</code> gives an error output in case no tags exist like:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{
    &quot;shortMessage&quot;: &quot;Command failed with exit code 1: npm view --json sompackage dist-tags&quot;,
    &quot;command&quot;: &quot;npm view --json sompackage dist-tags&quot;,
    &quot;exitCode&quot;: 1,
    &quot;stdout&quot;: &quot;&quot;,
    &quot;stderr&quot;: &quot;npm ERR! code E404\nnpm ERR! 404 Not Found - GET https://registry.npmjs.org/hayden-test-repo - Not found\nnpm ERR! 404 \nnpm ERR! 404  'hayden-test-repo@latest' is not in the npm registry.\nnpm ERR! 404 You should bug the author to publish it (or use the name yourself!)\nnpm ERR! 404 \nnpm ERR! 404 Note that you can also install from a\nnpm ERR! 404 tarball, folder, http url, or git url.\n{\n  \&quot;error\&quot;: {\n    \&quot;code\&quot;: \&quot;E404\&quot;,\n    \&quot;summary\&quot;: \&quot;Not Found - GET https://registry.npmjs.org/hayden-test-repo - Not found\&quot;,\n    \&quot;detail\&quot;: \&quot;\\n 'hayden-test-repo@latest' is not in the npm registry.\\nYou should bug the author to publish it (or use the name yourself!)\\n\\nNote that you can also install from a\\ntarball, folder, http url, or git url.\&quot;\n  }\n}\n\nnpm ERR! A complete log of this run can be found in:\nnpm ERR!     /Users/hayden/.npm/_logs/2021-04-12T14_41_53_367Z-debug.log&quot;,
    &quot;failed&quot;: true,
    &quot;timedOut&quot;: false,
    &quot;isCanceled&quot;: false,
    &quot;killed&quot;: false
}"><pre class="notranslate"><span class="pl-kos">{</span>
    <span class="pl-s">"shortMessage"</span>: <span class="pl-s">"Command failed with exit code 1: npm view --json sompackage dist-tags"</span><span class="pl-kos">,</span>
    <span class="pl-s">"command"</span>: <span class="pl-s">"npm view --json sompackage dist-tags"</span><span class="pl-kos">,</span>
    <span class="pl-s">"exitCode"</span>: <span class="pl-c1">1</span><span class="pl-kos">,</span>
    <span class="pl-s">"stdout"</span>: <span class="pl-s">""</span><span class="pl-kos">,</span>
    <span class="pl-s">"stderr"</span>: <span class="pl-s">"npm ERR! code E404\nnpm ERR! 404 Not Found - GET https://registry.npmjs.org/hayden-test-repo - Not found\nnpm ERR! 404 \nnpm ERR! 404  'hayden-test-repo@latest' is not in the npm registry.\nnpm ERR! 404 You should bug the author to publish it (or use the name yourself!)\nnpm ERR! 404 \nnpm ERR! 404 Note that you can also install from a\nnpm ERR! 404 tarball, folder, http url, or git url.\n{\n  \"error\": {\n    \"code\": \"E404\",\n    \"summary\": \"Not Found - GET https://registry.npmjs.org/hayden-test-repo - Not found\",\n    \"detail\": \"\\n 'hayden-test-repo@latest' is not in the npm registry.\\nYou should bug the author to publish it (or use the name yourself!)\\n\\nNote that you can also install from a\\ntarball, folder, http url, or git url.\"\n  }\n}\n\nnpm ERR! A complete log of this run can be found in:\nnpm ERR!     /Users/hayden/.npm/_logs/2021-04-12T14_41_53_367Z-debug.log"</span><span class="pl-kos">,</span>
    <span class="pl-s">"failed"</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span>
    <span class="pl-s">"timedOut"</span>: <span class="pl-c1">false</span><span class="pl-kos">,</span>
    <span class="pl-s">"isCanceled"</span>: <span class="pl-c1">false</span><span class="pl-kos">,</span>
    <span class="pl-s">"killed"</span>: <span class="pl-c1">false</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">The <code class="notranslate">stderr</code> contains the <code class="notranslate">json</code> response but also contains some text making the JSON unparsable.</p>
<h3 dir="auto">Expected Behavior:</h3>
<p dir="auto">We should be able to get a valid json in <code class="notranslate">stderr</code> without the extra string.</p>
<h3 dir="auto">Steps To Reproduce:</h3>
<ol dir="auto">
<li>Run npm view --json sompackage dist-tags</li>
<li>Observe the stderr being given.</li>
</ol>
<p dir="auto"><a href="https://github.com/sindresorhus/np/issues/600" data-hovercard-type="issue" data-hovercard-url="/sindresorhus/np/issues/600/hovercard">This issue</a> on <code class="notranslate">np</code> has more detailed info in case it is needed.</p>
<h3 dir="auto">Environment:</h3>
<ul dir="auto">
<li>OS: Ubuntu 20.04</li>
<li>Node: v14.16.1</li>
<li>npm: 7.9.0</li>
</ul>
<h3 dir="auto">The problem</h3>
<p dir="auto">NPM's <a href="https://docs.npmjs.com/cli/v6/using-npm/config#json" rel="nofollow">--json</a> 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.</p>
<p dir="auto">With NPM 7.x, everything is mixed together on STDERR. This defeats the point of the <code class="notranslate">--json</code> 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.</p>
<h3 dir="auto">Steps To Reproduce:</h3>
<ol dir="auto">
<li>
<p dir="auto"><strong>Correct behavior:</strong> With NPM 6.x, invoke this command:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="npm search --json"><pre class="notranslate"><code class="notranslate">npm search --json
</code></pre></div>
<p dir="auto">The JSON output is written to STDOUT:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{
  &quot;error&quot;: {
    &quot;code&quot;: null,
    &quot;summary&quot;: &quot;search must be called with arguments&quot;,
    &quot;detail&quot;: &quot;&quot;
  }
}"><pre class="notranslate"><span class="pl-kos">{</span>
  <span class="pl-s">"error"</span>: <span class="pl-kos">{</span>
    <span class="pl-s">"code"</span>: <span class="pl-c1">null</span><span class="pl-kos">,</span>
    <span class="pl-s">"summary"</span>: <span class="pl-s">"search must be called with arguments"</span><span class="pl-kos">,</span>
    <span class="pl-s">"detail"</span>: <span class="pl-s">""</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">The console messages are written to STDERR:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="npm ERR! search must be called with arguments
npm ERR! A complete log of this run can be found in:"><pre class="notranslate"><code class="notranslate">npm ERR! search must be called with arguments
npm ERR! A complete log of this run can be found in:
</code></pre></div>
</li>
<li>
<p dir="auto"><strong>Broken behavior:</strong> With NPM 7.5.4 (the latest version), invoke the same command.  Both outputs are mixed together on STDERR.  Nothing is written to STDOUT.</p>
</li>
</ol>
<p dir="auto">This regression appears to have been introduced with NPM 7.0.0.</p>
<h3 dir="auto">Environment:</h3>
<ul dir="auto">
<li>OS: All OS's</li>
<li>Node: 12.17.0</li>
<li>npm: 7.5.4</li>
</ul>