Skip to content
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

[BUG] [ReOpening] Having a file named node.js will be "run" instead of node #71

Open
1 task done
ckohen opened this issue Aug 4, 2022 · 0 comments
Open
1 task done
Labels
Priority 1 high priority issue

Comments

@ckohen
Copy link

ckohen commented Aug 4, 2022

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

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

  1. npm install a package with a bin script
  2. 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
  3. run the script via a script in package.json OR with npx
  4. 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
@ckohen ckohen added the Needs Triage needs an initial review label Aug 4, 2022
@lukekarrys lukekarrys added Priority 1 high priority issue and removed Needs Triage needs an initial review labels Dec 21, 2022
kevinoid added a commit to kevinoid/eslint-config-kevinoid that referenced this issue 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 (actions/setup-node#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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority 1 high priority issue
Projects
None yet
Development

No branches or pull requests

2 participants