Skip to content

[BUG] npx Fails to Execute Binaries Named After Shell Keywords #8190

Closed
@ycmjason

Description

@ycmjason

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

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:

$ npx @my-pkg/select
sh: -c: line 0: syntax error near unexpected token `newline'
sh: -c: line 0: `select'

$ npx "@my-pkg/if"
sh: -c: line 1: syntax error: unexpected end of file

Running the binaries directly using their full paths works without any issues:

$ node_modules/.bin/select
hello from select

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

  1. Clone the following repository: npx-shell-keyword-issue.
  2. Without running npm install, execute the following commands:
    npx @my-pkg/f
    npx @my-pkg/select
    npx @my-pkg/if
    
  3. Try quoting the binary names:
    npx '@my-pkg/select'
    npx "@my-pkg/if"
    
  4. Alternatively, run the binaries directly:
    node_modules/.bin/f
    node_modules/.bin/select
    node_modules/.bin/if
    

Environment

  • npm: 10.9.2
  • Node.js: v23.10.0
  • OS Name: MacOS 14.4.1
  • System Model Name: Macbook Pro 2021 M1 MAX
  • npm config:
ini; "user" config from /Users/ycmjason/.npmrc

//npm.pkg.github.com/:_authToken = (protected)
//registry.npmjs.org/:_authToken = (protected)

; node bin location = /Users/ycmjason/n/bin/node
; node version = v23.10.0
; npm local prefix = /Users/ycmjason/Development/000-bug-repro/npx-shell-keyword-issue
; npm version = 10.9.2
; cwd = /Users/ycmjason/Development/000-bug-repro/npx-shell-keyword-issue
; HOME = /Users/ycmjason
; Run `npm config ls -l` to show all defaults.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingPriority 2secondary priority issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions