-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Description
Is there an existing issue for this?
- I have searched the existing issues
Current Behavior
When I run npm install
in a project that has a "bin"
section in package.json
, the binary(s) specified doesn't get created in node_modules/.bin
.
Expected Behavior
I'd expect a script to be created in node_modules/.bin/ since that's the behavior documented at
https://docs.npmjs.com/cli/v7/configuring-npm/package-json#bin
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.
A user on StackOverflow seems to have found that this case is excluded intentionally in code, but couldn't find a reason.
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!)
Steps To Reproduce
- In any environment, AFAICT, with a simple script like
example.js
:
#!/usr/bin/env node
console.log("Hello, world!")
- And a
package.json
that references it:
{
"name": "npm-bug",
"version": "1.0.0",
"description": "",
"main": "example.js",
"bin": "example.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
-
Run
npm install
-
And observe that there's no script created in
node_modules/.bin/
Aha. Recreating this fresh, I may have found the reasoning behind this exception -- if you have no dependencies, there isn't a node_modules/
or node_modules/.bin/
directory to install the script into.
However, that's probably the rare case. Often, such packages will have dependencies, so node_modules/.bin/
will exist, which makes the script's absence from it all the more confusing.
Environment
- OS: Windows 10
- Node: v14.17.0
- npm: 7.19.0 (But I also observed this behavior on 6.14.x)