<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="  Original bug ticket: [https://npm.community/t/9164](https://npm.community/t/9164)
  Originally filed: 2019-07-29T19:05:16.541Z"><pre class="notranslate"><code class="notranslate">  Original bug ticket: [https://npm.community/t/9164](https://npm.community/t/9164)
  Originally filed: 2019-07-29T19:05:16.541Z
</code></pre></div>
<hr>
<p dir="auto">From original issue: <a href="https://npm.community/t/9164" rel="nofollow">https://npm.community/t/9164</a><br>
Debug log: n/a<br>
Action triggered: <code class="notranslate">sudo npm install -g npm</code></p>
<p dir="auto">Platform info: (incomplete)</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ npm --versions
6.9.0
$ node -p process.platform
darwin"><pre class="notranslate"><code class="notranslate">$ npm --versions
6.9.0
$ node -p process.platform
darwin
</code></pre></div>
<p dir="auto">Additional information:</p>
<ul dir="auto">
<li>reference to a blog post which indicates solving the problem with an update of <code class="notranslate">npm</code> and clearing the cache.</li>
</ul>
<h3 dir="auto">Is there an existing issue for this?</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have searched the existing issues</li>
</ul>
<h3 dir="auto">Current Behavior</h3>
<p dir="auto">When I run <code class="notranslate">npm install</code> in a project that has a <code class="notranslate">"bin"</code> section in <code class="notranslate">package.json</code>, the binary(s) specified doesn't get created in <code class="notranslate">node_modules/.bin</code>.</p>
<h3 dir="auto">Expected Behavior</h3>
<p dir="auto">I'd expect a script to be created in node_modules/.bin/ since that's the behavior documented at<br>
<a href="https://docs.npmjs.com/cli/v7/configuring-npm/package-json#bin" rel="nofollow">https://docs.npmjs.com/cli/v7/configuring-npm/package-json#bin</a></p>
<blockquote>
<p dir="auto">To use this, supply a bin field in your package.json which is a map of command name to local file name. On install, npm will symlink that file into prefix/bin for global installs, or ./node_modules/.bin/ for local installs.</p>
</blockquote>
<p dir="auto">A user <a href="https://stackoverflow.com/questions/50140514/why-does-npm-install-in-a-package-ignore-bin-in-the-top-level-package-json" rel="nofollow">on StackOverflow</a> seems to have found that this case is excluded intentionally in code, but couldn't find a reason.</p>
<p dir="auto">The code and the documentation are mismatched currently, in a way that eats developer time. One or the other should probably be updated so that they match.  (IMO, I'd prefer a script be installed in this case, because sometimes I want to use a package's script without installing it globally!)</p>
<h3 dir="auto">Steps To Reproduce</h3>
<ol dir="auto">
<li>In any environment, AFAICT, with a simple script like <code class="notranslate">example.js</code>:</li>
</ol>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="#!/usr/bin/env node

console.log(&quot;Hello, world!&quot;)"><pre class="notranslate">#!/usr/bin/env node

<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">"Hello, world!"</span><span class="pl-kos">)</span></pre></div>
<ol start="2" dir="auto">
<li>And a <code class="notranslate">package.json</code> that references it:</li>
</ol>
<div class="highlight highlight-source-json notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{
  &quot;name&quot;: &quot;npm-bug&quot;,
  &quot;version&quot;: &quot;1.0.0&quot;,
  &quot;description&quot;: &quot;&quot;,
  &quot;main&quot;: &quot;example.js&quot;,
  &quot;bin&quot;: &quot;example.js&quot;,
  &quot;scripts&quot;: {
    &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;
  },
  &quot;author&quot;: &quot;&quot;,
  &quot;license&quot;: &quot;ISC&quot;
}"><pre class="notranslate">{
  <span class="pl-ent">"name"</span>: <span class="pl-s"><span class="pl-pds">"</span>npm-bug<span class="pl-pds">"</span></span>,
  <span class="pl-ent">"version"</span>: <span class="pl-s"><span class="pl-pds">"</span>1.0.0<span class="pl-pds">"</span></span>,
  <span class="pl-ent">"description"</span>: <span class="pl-s"><span class="pl-pds">"</span><span class="pl-pds">"</span></span>,
  <span class="pl-ent">"main"</span>: <span class="pl-s"><span class="pl-pds">"</span>example.js<span class="pl-pds">"</span></span>,
  <span class="pl-ent">"bin"</span>: <span class="pl-s"><span class="pl-pds">"</span>example.js<span class="pl-pds">"</span></span>,
  <span class="pl-ent">"scripts"</span>: {
    <span class="pl-ent">"test"</span>: <span class="pl-s"><span class="pl-pds">"</span>echo <span class="pl-cce">\"</span>Error: no test specified<span class="pl-cce">\"</span> &amp;&amp; exit 1<span class="pl-pds">"</span></span>
  },
  <span class="pl-ent">"author"</span>: <span class="pl-s"><span class="pl-pds">"</span><span class="pl-pds">"</span></span>,
  <span class="pl-ent">"license"</span>: <span class="pl-s"><span class="pl-pds">"</span>ISC<span class="pl-pds">"</span></span>
}</pre></div>
<ol start="3" dir="auto">
<li>
<p dir="auto">Run <code class="notranslate">npm install</code></p>
</li>
<li>
<p dir="auto">And observe that there's no script created in <code class="notranslate">node_modules/.bin/</code></p>
</li>
</ol>
<hr>
<p dir="auto">Aha. Recreating this fresh, I may have found the reasoning behind this exception -- if you have no dependencies, there isn't a <code class="notranslate">node_modules/</code> or <code class="notranslate">node_modules/.bin/</code> directory to install the script into.</p>
<p dir="auto">However, that's probably the rare case. Often, such packages will have dependencies, so <code class="notranslate">node_modules/.bin/</code> will exist, which makes the script's absence from it all the more confusing.</p>
<h3 dir="auto">Environment</h3>
<ul dir="auto">
<li>OS: Windows 10</li>
<li>Node: v14.17.0</li>
<li>npm: 7.19.0 (But I also observed this behavior on 6.14.x)</li>
</ul>