Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 task done
tbremer opened this issue May 14, 2021 · 4 comments
Closed
1 task done
Assignees
Labels
Bug thing that needs fixing cmd:exec related to `npx` Priority 2 secondary priority issue Release 7.x work is associated with a specific npm 7 release

Comments

@tbremer
Copy link

tbremer commented May 14, 2021

Is there an existing issue for this?

  • 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 tbremer added Bug thing that needs fixing Needs Triage needs review for next steps Release 7.x work is associated with a specific npm 7 release labels May 14, 2021
@ruyadorno ruyadorno added Priority 2 secondary priority issue and removed Needs Triage needs review for next steps labels Jan 24, 2022
@ruyadorno
Copy link
Collaborator

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.

@fritzy fritzy added the cmd:exec related to `npx` label Jul 25, 2022
@wraithgar wraithgar self-assigned this Aug 2, 2022
@wraithgar
Copy link
Member

wraithgar commented Aug 11, 2022

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.

@tbremer
Copy link
Author

tbremer commented Aug 11, 2022

@wraithgar thanks for explaining and fixing the issue! 🎉

@wraithgar
Copy link
Member

~/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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing cmd:exec related to `npx` Priority 2 secondary priority issue Release 7.x work is associated with a specific npm 7 release
Projects
None yet
Development

No branches or pull requests

4 participants