[BUG] `npx` "Need to install" message with local CLI that has no dependencies
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
- Clone this repository: https://github.com/tbremer/npx-local-cli-issue
- Run
npx .at the root directory
Environment
OS:
ProductName: macOS
ProductVersion: 11.2.3
BuildVersion: 20D91
- Node: v16.1.0
- npm: 7.11.2
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.
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 thanks for explaining and fixing the issue! 🎉
~/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