Skip to content

fix(exec): run the .cmd shim of a bin with a dot in its name on Windows - #10199

Open
b84330808 wants to merge 1 commit into
npm:latestfrom
b84330808:fix/exec-windows-dotted-bin-cmd-shim
Open

b84330808 wants to merge 1 commit into
npm:latestfrom
b84330808:fix/exec-windows-dotted-bin-cmd-shim

Conversation

@b84330808

Copy link
Copy Markdown

What / Why

On Windows, npx / npm exec can't run a bin whose name has a . in it (for example npx npm.windows-bin-issue, or the only bin of a package like @org/namespace.foo). Nothing runs: Windows opens the file with whatever program is registered for the "extension" instead.

cmd.exe looks up a command that already has an extension by that exact name before it tries PATHEXT, so it finds the extensionless sh shim in node_modules/.bin instead of the .cmd next to it. npm/exec#17 already described the fix: run the .cmd shim directly instead of letting the shell resolve the extension.

libnpmexec's run-script.js now does that on Windows. If the bin name has an extension and a <bin>.cmd exists in binPaths or in a node_modules/.bin above runPath, it runs <bin>.cmd. Names without a dot, and commands without a .cmd shim, are unchanged.

Testing

A new case in workspaces/libnpmexec/test/run-script.js covers a shim in binPaths, a shim in a node_modules/.bin above runPath, and a dotted name with no shim. The first two fail without the change (dot.bin instead of dot.bin.cmd). The libnpmexec suite passes on Windows 11 with 100% coverage, and test/lib/commands/exec.js passes.

On Windows 11, with a package whose bin is dot.bin, node . exec dot.bin hello world now prints the script's output, both for a locally installed package and through the npx cache (--package=<dir>). With npm 11.12.1 the same command printed nothing.

References

Fixes #8518

I used Claude Code to write this change.

cmd.exe looks up a command that already has an extension by that exact
name before it tries PATHEXT. For a bin like `npm.windows-bin-issue`
that finds the extensionless sh shim in node_modules/.bin, and Windows
opens it with whatever program is registered for the "extension"
instead of running it, so `npx` prints nothing.

When the bin name has a dot and a .cmd shim for it exists in binPaths
or in a node_modules/.bin above runPath, run the .cmd shim directly.

Fixes npm#8518

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@b84330808
b84330808 requested a review from a team as a code owner November 1, 2026 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] npx/exec unable to run bin scripts with . in name on Windows

1 participant