Navigation Menu

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

Windows & Git Bash: yarn run fails due to missing slashes #7732

Open
oturpe opened this issue Dec 3, 2019 · 8 comments
Open

Windows & Git Bash: yarn run fails due to missing slashes #7732

oturpe opened this issue Dec 3, 2019 · 8 comments

Comments

@oturpe
Copy link

oturpe commented Dec 3, 2019

Do you want to request a feature or report a bug?
A bug

What is the current behavior?
Under Windows, when using Git Bash as the script-shell, attempts to run executables from node_modules/.bin using the yarn <executable> syntax fail due to path corruption.

If the current behavior is a bug, please provide the steps to reproduce.

  1. Clone the following repository: https://github.com/oturpe/yarn-run-bug
  2. Install dependencies with yarn
  3. Try to run an executable installed in node_modules/.binwith yarn eslint
  4. Observe execution fails due to the path corruption like this:
PS C:\ws\Testit\NodeJs\yarn-run> yarn eslint
yarn run v1.21.0
$ C:\ws\Testit\NodeJs\yarn-run\node_modules\.bin\eslint
/usr/bin/bash: C:wsTestitNodeJsyarn-runnode_modules.bineslint: command not found
error Command failed with exit code 127.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

What is the expected behavior?
Path is translated successfully and yarn eslint is run.

Please mention your node.js, yarn and operating system version.
NodeJs: 12.13.1
Yarn: 1.21.0
Operating system: Microsoft Windows [Version 10.0.18363.476]

@bartlomiejzuber
Copy link

I have the same issue.
NodeJs: 13.9.0
Yarn: 1.21.0
Operating system: Microsoft Windows [Version 10.0.18363.476]

@Atsushi-Haba
Copy link

My solution, add script to package.json

"scripts": {
  ...,
  "lint" : "eslint"
}

then yarn lint will work well

@cejaramillof
Copy link

cejaramillof commented Dec 8, 2020

i have the same issue (cmd, gitbash, bash), did anyone find the solution?

@bartlomiejzuber
Copy link

bartlomiejzuber commented Dec 9, 2020

i have the same issue (cmd, gitbash, bash), did anyone find the solution?

I simply reinstalled the system and it worked. But that's probably not the solution you're looking for. It happened for me at least twice and I suspect the issue is somewhere inside git bash for windows.

@cejaramillof
Copy link

i have the same issue (cmd, gitbash, bash), did anyone find the solution?

I simply reinstalled the system and it worked. But that's probably not the solution you're looking for. It happened for me at least twice and I suspect the issue is somewhere inside git bash for windows.

thanks you, I think not is related with git bash, because I have the same issue in cmd and powershell, I try repair yarn and not works :( Addin like script in package.json, but I'm curious about the error.

Thank you for your help!

@cejaramillof
Copy link

cejaramillof commented Dec 15, 2020

Ey, youre right. The problem was with gitbash.
I change the paths of shell and script-shell in yarn config list for C:\\WINDOWS\\system32\\cmd.exe and now is working.

@Noah2610
Copy link

I've been debugging this for a bit, here's what I learned:

Scenario

Let's follow the original scenario:

What happens when we run yarn eslint

When we run yarn run eslint, yarn will find the full path to the locally installed eslint (1), which will be something like this (on Windows): <project-path>\node_modules\.bin\eslint
This command is then escaped using puka's quoteForShell function (2, also quoted with sh 3).
The quoteForShell function escapes the string for the current platform, and not for the script-shell.
So our command is quoted for Windows, but then run on Bash.
We want to quote our command for Linux/MacOS/*nix because our script-shell is Bash, even though we're running on Windows.

This feels like a yarn bug, because it is quoting the command for the wrong environment in this situation.

Possible solutions

Possible solutions to fix this behavior inside yarn's codebase.
Note, that none of these solutions have been properly tested.

  1. Always force-quote every command.
    When we quote the command using puka.quoteForShell (2),
    we can add true as a second argument to force-quote the string:
    quoteForShell(command, true)
  2. Check the current platform and the script-shell to determine for which platform to quote.
    Example: If on Windows, but using git-bash, then quote for Linux (puka.quoteForSh).

@mateustalles
Copy link

Ey, youre right. The problem was with gitbash. I change the paths of shell and script-shell in yarn config list for C:\\WINDOWS\\system32\\cmd.exe and now is working.

Thanks, that worked for me!

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

No branches or pull requests

6 participants