cli icon indicating copy to clipboard operation
cli copied to clipboard

[BUG] `npx` "Need to install" message with local CLI that has no dependencies

Open tbremer opened this issue 4 years ago • 2 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Might be related to: #2627

Current Behavior

I have a project there the root contains a CLI. The package.json looks like this:

{
  "name": "name",
  "private": true,
  "scripts": {},
  "bin": "./cli.mjs",
  "devDependencies": {
    "prettier": "^2.3.0"
  }
}

When I run npx . I am given the following message:

$ npx .
Need to install the following packages:
  file:
Ok to proceed? (y)

The CLI does not have any dependencies, and the file is stored locally on the file system. There is nothing to install and the message is incomplete.

Expected Behavior

CLI should execute without prompting the user as there is nothing to install.

Steps To Reproduce

  1. Clone this repository: https://github.com/tbremer/npx-local-cli-issue
  2. Run npx . at the root directory

Environment

OS:

ProductName:	macOS
ProductVersion:	11.2.3
BuildVersion:	20D91
  • Node: v16.1.0
  • npm: 7.11.2

tbremer avatar May 14 '21 23:05 tbremer

Can confirm with a minimal repro:

$ cat package.json
{
  "name": "npm-exec-self",
  "version": "1.0.0",
  "bin": "index.js"
}

$ cat index.js
console.log('hello')

$ npm exec .
Need to install the following packages:
  file:/Users/ruyadorno/tmp/npm-exec-self
Ok to proceed? (y)

Same can be observed using any variation:

npm exec file:. npm exec file:/path/to/folder

It would make sense from an implementation point of view since arborist doesn't make a difference and it will need to install (or link) the package to the npx user space but it would make sense to skip this message given that this is a local folder.

ruyadorno avatar Jan 24 '22 23:01 ruyadorno

The reason you get this message is because the local package does actually have to install. A package as-is doesn't have its bin entries linked properly, so npx has to "install" the package in into its .npx folder just like any other package.

You're right that this isolated use case shouldn't prompt though, it should just install and run it. #5298 does this.

wraithgar avatar Aug 11 '22 16:08 wraithgar

@wraithgar thanks for explaining and fixing the issue! 🎉

tbremer avatar Aug 11 '22 17:08 tbremer

~/D/n/gar-create-test (main|✔) $ npm -v
8.18.0
~/D/n/gar-create-test (main|✔) $ npx .
Gar's test create script version 2.0.3

wraithgar avatar Aug 18 '22 14:08 wraithgar