Skip to content

fix: Fixed an issue with files named node.js on Windows#64

Merged
owlstronaut merged 3 commits into
npm:mainfrom
giovannicalo:main
Jun 19, 2026
Merged

fix: Fixed an issue with files named node.js on Windows#64
owlstronaut merged 3 commits into
npm:mainfrom
giovannicalo:main

Conversation

@giovannicalo

Copy link
Copy Markdown
Contributor

When a Node module binary is run in a folder containing a file called node.js, on Windows, that file will be opened instead of the binary.

This happens due to Windows' PATHEXT environment variable containing .JS.

The issue was originally fixed in 8b1433c, but it has reappeared in c039646.

Currently, endlocal is called after editing PATHEXT but before invoking Node, so the latter is not affected by it.

My solution edits PATHEXT after calling endlocal, thus affecting the Node invocation and fixing the issue.

The only downside is the Node process will receive the edited PATHEXT, which however must've been the original behaviour anyway.

@giovannicalo giovannicalo requested a review from a team as a code owner April 18, 2022 02:25
@giovannicalo giovannicalo changed the title Fixed an issue with files named node.js on Windows Fix: Fixed an issue with files named node.js on Windows Apr 22, 2022
kevinoid added a commit to kevinoid/eslint-config-kevinoid that referenced this pull request May 7, 2023
To avoid inadvertently running node.js (using Windows Script Host)
instead of node.exe when .js is present in %PATHEXT% (as it is by
default).  The problem is exacerbated by a regression in .cmd shims
generated by npm (npm/cmd-shim#64
npm/cmd-shim#71) and has already caused
problems in CI (https://github.com/actions/setup-node/issues/720).

Continue to export node and node.js from the package for backward
compatibility.  These may be removed in a future version.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
@owlstronaut

Copy link
Copy Markdown
Contributor

Sorry this got stale. Reopen a pr if it is still good/relevant

@owlstronaut owlstronaut closed this Jun 8, 2026
kevinoid added a commit to kevinoid/setup-node-issue-720 that referenced this pull request Jun 10, 2026
See: npm/cmd-shim#71
See: npm/cmd-shim#64
Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
@kevinoid

kevinoid commented Jun 10, 2026

Copy link
Copy Markdown

@owlstronaut I can still reproduce the issue in main (6ea7b53) by running (in cmd.exe):

echo #!/usr/bin/env node >mycommand.js
echo console.log('Success!') >>mycommand.js
md bin
node -e "require('cmd-shim')('mycommand.js', 'bin/mycommand')"
type nul >bin/node.js
cd bin
mycommand

I can also confirm that this PR still applies cleanly and fixes the issue, as demonstrated by a Github Actions Workflow.

I urge you to consider reopening and merging this PR.

@owlstronaut owlstronaut reopened this Jun 10, 2026
@owlstronaut

Copy link
Copy Markdown
Contributor

@kevinoid great, I've reopened it. Happy to take a look when CI is happy :)

@giovannicalo

Copy link
Copy Markdown
Contributor Author

It seems in the last 4 years a test has been added which my original commit didn't cover.

I've updated the snapshot. It should pass now.

@owlstronaut owlstronaut changed the title Fix: Fixed an issue with files named node.js on Windows fix: Fixed an issue with files named node.js on Windows Jun 19, 2026
@owlstronaut owlstronaut merged commit 1c2f94c into npm:main Jun 19, 2026
23 of 24 checks passed
@github-actions github-actions Bot mentioned this pull request Jun 19, 2026
owlstronaut pushed a commit that referenced this pull request Jun 19, 2026
🤖 I have created a release *beep* *boop*
---


## [9.0.2](v9.0.1...v9.0.2)
(2026-06-19)
### Bug Fixes
*
[`1c2f94c`](1c2f94c)
[#64](#64) Fixed an issue with files
named node.js on Windows (#64) (@giovannicalo)
### Chores
*
[`4f2209b`](4f2209b)
[#185](#185) bump
@npmcli/template-oss from 5.1.0 to 5.1.1 (#185) (@dependabot[bot],
@npm-cli-bot)

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

3 participants