Skip to content

[BUG] npm install does not set up commands defined in bin #526

Description

@jgehrcke

The bin section in the package.json documentation says

On install, npm will symlink that file into prefix/bin for global installs, or ./node_modules/.bin/ for local installs.

However, that does not seem to happen.

Repro

$ cat package.json
{
  "name": "bin-install-repro",
  "version": "1.0.0",
  "private": true,
  "description": "",
  "scripts": {
    "tsc": "tsc",
    "main": "main"
  },
  "bin": {
    "main": "./main.js"
  },
  "author": "",
  "license": "",
  "dependencies": {}
}
$ cat main.js
#!/usr/bin/env node
console.log("hello universe");
$ npm install .
up to date in 0.445s
found 0 vulnerabilities
$ npm run main

> bin-install-repro@1.0.0 main /home/jp/dev/bin-install-issue
> main

sh: main: command not found
$ ls $(npm bin)
total 0

As we know this can be achieved with npm link, which is documented with

It will also link any bins in the package to {prefix}/bin/{name}.

$ npm link
...
$ npm run main

> bin-install-repro@1.0.0 main /home/jp/dev/bin-install-issue
> main

hello universe

Environment

$ node --version
v12.13.1
$ npm --version
6.12.1

Is the documentation bad, or the implementation? :)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixing

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions