-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[BUG] npx
Fails to Execute Binaries Named After Shell Keywords
#8190
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
Comments
A workaround for this issue is to define a non-shell keyword name in For example:
This changes the binary name to See also: https://github.com/fishballapp/inquirer-cli/blob/main/packages/select/package.json#L7 |
A better way would be fixing npm to only look for binaries/packages inside of where it installs global/local modules. |
100%! I wanted to help other developers facing this issue by offering a temporary workaround. Implementing a proper fix will probably take some time. Even after the fix is shipped, libraries would probably still want to keep the workaround for a while until the majority of users have upgraded beyond the patched release. |
@ycmjason I made this wrapper for bun: #!/usr/bin/sh -e
# Usage: remove list item
remove() {
first=1
item=$2
IFS=':' set -- $1
for dir in $@; do
if [ "$dir" != "$item" ]; then
if [ $first -eq 1 ]; then
printf "$dir"
first=0
else
printf ":$dir"
fi
fi
done
}
PATH=$(remove "$PATH" "/bin")
PATH=$(remove "$PATH" "/usr/bin")
PATH=$(remove "$PATH" "/usr/local/bin")
PATH=$(remove "$PATH" "/sbin")
PATH=$(remove "$PATH" "/usr/sbin")
PATH=$(remove "$PATH" "/usr/local/sbin")
bun $* It could be smaller but this way is more extendable. It doesn't work for npx unfortunately, as it requires |
Btw, this is where the commands are being executed: https://github.com/npm/cli/blob/latest/lib/cli/entry.js#L58 it runs commands with It seems also to run inside another shell which makes a wrapper useless. How I discovered it:I took the code above and replace #!/usr/bin/sh -e
node $* and running And running just |
The previous pull request doesn't fix my issue. I found a way tho: removing this line https://github.com/npm/cli/blob/latest/lib/commands/exec.js#L90 solves the issue of executing programs instead of node modules. Tho it fixes my problem this seems to be a "feature" of npm. So I'll not be able to make a pull request unless npm maintainers give up on this feature. |
Is there an existing issue for this?
This issue exists in the latest npm version
Current Behavior
When using
npx
to execute binaries whose names match shell keywords (e.g.,select
,if
), the execution fails with syntax errors. This issue occurs even when the binary name is quoted using single or double quotes.The reproduction repo can be found: https://github.com/ycmjason/npx-shell-keyword-issue
Description
npx
fails to execute binaries named after shell keywords, producing syntax errors. For example:Running the binaries directly using their full paths works without any issues:
Actual Behavior
npx
fails to execute binaries named after shell keywords, producing syntax errors.Use Case
I am attempting to port
@inquirer/select
to a binary under@inquirer-cli/select
. As I was testing my binaries, I noticed@inquirer-cli/select
is the only one that wouldn't run.See https://github.com/fishballapp/inquirer-cli?tab=readme-ov-file#inquirer-cliselect
Expected Behavior
npx
should execute binaries correctly, even if their names match shell keywords.Steps To Reproduce
npm install
, execute the following commands:Environment
The text was updated successfully, but these errors were encountered: