[BUG] [ReOpening] Having a file named node.js will be "run" instead of node
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 48/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- javascript
- Domain
- operating-systems, tooling
Research direction
Start by inspecting cmd-shim's Windows-generated shim and compare its behavior with the npm and Yarn shim examples in the issue. Reproduce the problem by placing node.js beside package.json and running a package bin script or npx command on Windows. Done means the intended bin JavaScript file runs through the node executable instead of the local node.js file.
Written by the indexing model from the issue text.
Description
Is there an existing issue for this?
- I have searched the existing issues
The existing issue was closed with the reason JS shouldn't be in your pathext environment variable. While that is a solution, it is a completely invalid solution from my perspective.
It took me 2 hours of debugging to identify that was the problem, and in case you were unaware, that is the default in Windows. Though it certainly seems like you are aware given you attempt to remove it in the shim. Now that I know what it is, its an easy fix, but that's a terrible developer experience and needs fixing.
Current Behavior
- As described in #40 the node.js file will be "run" by the OS instead of running the node executable located somewhere in path
- After inspecting the output shim, it appears there was an attempt to fix this, but it does not work.
For reference, npms generated shim for rimraf:
@ECHO off
GOTO start
:find_dp0
SET dp0=%~dp0
EXIT /b
:start
SETLOCAL
CALL :find_dp0
IF EXIST "%dp0%\node.exe" (
SET "_prog=%dp0%\node.exe"
) ELSE (
SET "_prog=node"
SET PATHEXT=%PATHEXT:;.JS;=;%
)
endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\..\rimraf\bin.js" %*
Expected Behavior
- Running whatever bin js file is supposed to run as it does when yarn correctly generates this shim.
For reference, yarns generated shim for rimraf:
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\..\rimraf\bin.js" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node "%~dp0\..\rimraf\bin.js" %*
)
Steps To Reproduce
- npm install a package with a bin script
- create a file called node.js in the same directory as the package.json you will be running scripts from OR the directory you run the command directly from
- run the script via a script in package.json OR with npx
- notice the file opens and the script never runs
Environment
- npm: 8.16.0
- Node: 16.15.1
- OS: Windows 10 Home 21H2 (19044.1826)
- platform: Desktop
- Dominant language
- JavaScript
- Stars
- 81
- Forks
- 51
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from npm/cmd-shim
-
Needs Triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
[BUG] PowerShell shim generated as UTF-8 without BOM breaks on Windows PowerShell 5 with non-ASCII pathsPossibly taken @webywz claimed this 32 days ago. OpenNeeds Triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Needs Triage
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
Needs Triage
Difficulty 3/5 1-2 days Newbie friendliness 45/100
-
[BUG] .cmd @echo offOpenNeeds Triage
Difficulty 3/5 1-2 days Newbie friendliness 45/100
Similar issues
-
question
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
bug has-work-around priority: high
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
liberation-data/drivine#908 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
JoeyHammoth/SolidGround#99 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Flow Needs: Triage :mag:
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
react/react-native#60447 ·
Maintainers usually reply within 1 day