-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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] "yarn node" command sometimes uses wrong node.exe on Windows #1377
Comments
I've tested this and can reproduce it on PowerShell, though it works fine in git BASH. Ignore the mention above, I thought it worked after a fix for another PR but I was testing in BASH. Old (false) theory explaining the issue, see comment below instead![screenshot of correct output in BASH and faulty output in PowerShell](https://user-images.githubusercontent.com/821510/82564016-556fea00-9b78-11ea-8a88-a19b02b05fbb.png)The issue lies with PATHEXT. The windows shells CMD and PowerShell search all folders in the PATH not just for files matching the executable's name, but also for those matching the executable's name with one of the PATHEXT file extensions. C:\Some\Folder> yarn exec where node
C:\Users\User\AppData\Temp\xfs-hash\node <-- note, I'm running code with #1386 in it, so the if you use the master branch yarn will not log this line
C:\Users\User\AppData\Temp\xfs-hash\node.cmd
C:\Program Files\nodejs\node.exe You'd think Windows will execute the first file it finds, but sadly the order of PATHEXT prevails over the order of PATH, and PATHEXT is C:\Some\Folder> $Env:PATHEXT
.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY;.PYW;.CPL
C:\Some\Folder> node --version
14.3.0
C:\Some\Folder> C:\path\to\node-12\node --version
12.16.3
C:\Some\Folder> C:\path\to\node-12\node .yarn/releases/yarn-berry.js exec node --version
14.3.0
C:\Some\Folder> C:\path\to\node-12\node .yarn/releases/yarn-berry.js exec node.cmd --version
12.16.3 The reason it works if you have I'm going out on a limb here and say this is probably one of the reasons for npm's |
Okay, I've looked into this some more, and we're in a pretty unique situation. First things first: I've opened moxystudio/node-cross-spawn#133 to fix this bug. What exactly is going on? Let's start with some context:
What's happening?
|
This version fixes a bug where node was resolved to the wrong binary on Windows, resulting in the wrong version of node being called if yarn is executed with a node version that's not the first node on the PATH. Fixes yarnpkg#1377
* Update cross-spawn This version fixes a bug where node was resolved to the wrong binary on Windows, resulting in the wrong version of node being called if yarn is executed with a node version that's not the first node on the PATH. Fixes #1377 * chore: update lockfile * chore: update cache Co-authored-by: merceyz <[email protected]>
yarn node
sometimes doesn't resolve node.exe to the one Yarn was started with. This has only happened on Windows.To Reproduce
yarn node
using a predefined path to node.exe and Yarn: e.g...\path-to-node\node.exe ..\path-to-yarn\yarn-berry.js node
This means only this works properly:
.\node.exe ..\path-to-yarn\yarn-berry.js node ...
This doesn't (uses node.exe from PATH):
..\any-other-path\node.exe ..\path-to-yarn\yarn-berry.js node ...
Environment
The text was updated successfully, but these errors were encountered: