Skip to content

BREAKING CHANGE(bin): command should not return non-existent paths #479

@ghost

Description

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

Run npm bin in a directory that doesn't have a package.json and isn't a child of a directory that does. Currently npm bin returns a string with ${pwd}/node_modules/.bin even if it doesn't exist.

Expected Behavior

I'm not sure what I expected, but I didn't expect npm bin to present a path to a non-existent directory.

Barring a backwards breaking change to the tool, an option like --strict would be a reasonable way to add the behavior. It's fairly trivial to test the path that gets returned, but it generates a bit more work than throwing a flag behind npm bin

Steps To Reproduce

  1. mac or linux ( didn't test on windows )
  2. no config necessary
$ cd /tmp
$ ls node_modules
ls: node_modules: No such file or directory
$ npm bin
/private/tmp/node_modules/.bin
$ 

Environment

  • npm: 8.3.1
  • Node.js: 17.3.1
  • OS Name: macOS 12.1
  • System Model Name: m1 air
  • npm config:
$ npm config ls
; "user" config from /Users/lineus/.npmrc

//registry.npmjs.org/:_authToken = (protected) 

; node bin location = /Users/lineus/.nvm/versions/node/v17.3.1/bin/node
; cwd = /private/tmp
; HOME = /Users/lineus
; Run `npm config ls -l` to show all defaults.
$ 

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions