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

yarn run doesn't work in Git Bash due to strange path modification #5717

Open
borekb opened this issue Apr 23, 2018 · 17 comments
Open

yarn run doesn't work in Git Bash due to strange path modification #5717

borekb opened this issue Apr 23, 2018 · 17 comments
Assignees
Labels

Comments

@borekb
Copy link

borekb commented Apr 23, 2018

Yarn 1.6.0, Git Bash on Windows and this package.json:

{
  "name": "test",
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "start": "MSYS_NO_PATHCONV=1 docker run --rm -it -p 8000:8000 -v `pwd`:/docs squidfunk/mkdocs-material:2.6.3"
  }
}

npm start works fine, yarn start displays this error:

$ yarn start
yarn run v1.6.0
$ MSYS_NO_PATHCONV=1 docker run --rm -it -p 8000:8000 -v `pwd`:/docs squidfunk/mkdocs-material:2.6.3
/c/Program Files/git/usr/bin/bash: Files\git\bin\bash.exe: No such file or directory
?[2K?[1G?[31merror?[39m Command failed with exit code 127.
?[2K?[1G?[94minfo?[39m Visit ?[1mhttps://yarnpkg.com/en/docs/cli/run?[22m for documentation about this command.

Node v8.10.0, I'm on Windows 10 Pro.

I think this is a regression and was working fine in Yarn 1.5.x.

@ghost ghost assigned Daniel15 Apr 23, 2018
@ghost ghost added the triaged label Apr 23, 2018
@chakrihacker
Copy link

/usr/bin/zsh: can't open input file: parcel index.html
error Command failed with exit code 127.

Same problem with ubuntu after upgrading to 1.6.x

@borekb
Copy link
Author

borekb commented Apr 26, 2018

The only workaround I found was downgrading to 1.5.1, Yarn was unusable with this bug, unfortunately.

@KatieMFritz
Copy link

Same problem here.

.yarnrc:

script-shell "C:\\Program Files\\Git\\bin\\bash.exe"
shell "C:\\Program Files\\Git\\bin\\bash.exe"

Terminal:

/usr/bin/bash: Files\Git\bin\bash.exe: No such file or directory

Tried escaping the space (Program\ Files) and using the shortname (PROGRA~) but neither worked.

Node 9.4.0, Windows 10 Pro

@infogulch
Copy link

infogulch commented May 1, 2018

Also fails using:

script-shell "\"C:\\Program Files\\Git\\bin\\bash.exe\""

With:

Cannot find executable: "C:\Program Files\Git\bin\bash.exe"

Downgrading to 1.5.1...

@borekb
Copy link
Author

borekb commented May 24, 2018

Just to confirm, the issue is still present in 1.7.0.

@martinmckenna
Copy link

Also confirming @KatieMFritz's issue.

After downgrading to yarn 1.5.1 from 1.7.0, the whitespace issue is resolved

@borekb
Copy link
Author

borekb commented Jul 28, 2018

FYI, I now run Yarn in Git Bash (actually MSYS2 shell with zsh) via an alias like this:

alias yarn='winpty yarn.cmd'

I believe this is the correct way to run Yarn in Git Bash anyway so this resolves the issue for me.

Unfortunately, Git Bash still cannot be used as a script-shell, see #6086, which is another show-stopper for me. So I'm still on 1.5.1 (it's probably just incidental that both issues started appearing in 1.6.0).

@borekb
Copy link
Author

borekb commented Jul 28, 2018

If you need to be on the latest version of Yarn and run it from Git Bash & use Git Bash as the shell-script, this combination should probably work:

  • Run Yarn through winpty: alias yarn='winpty yarn.cmd'
  • Instead of yarn run script, use npm run script

Hopefully Yarn will be fully compatible with Git Bash soon again.

@KatieMFritz
Copy link

Has anyone tried this with Yarn 1.9.2?

@dmclean77
Copy link

I just tried with v1.9.4 still doesn't work

@borekb
Copy link
Author

borekb commented Sep 21, 2018

A quick update:

1. winpty issue

For the first issue with winpty (path translation), I now use a small wrapper script that is in my PATH before node location, called yarn:

#!/bin/sh

winpty node.exe "C:\\Users\\${USER}\\AppData\\Local\\nvs\\default\\node_modules\\yarn\\bin\\yarn.js" "$@"
ret=$?
exit $ret

I then install Yarn with npm i -g yarn@1.5.1 (or any other version) and it will run through winpty.

2. script-shell issue

The other issue is with Bash / zsh being script-shell after which every yarn run command fails with something like:

zsh: can't open input file: /d

The main issue for this is #6086 and an upstream fix in Node.js has actually been merged a couple of weeks ago: nodejs/node#21943. However, this will be released only in Node 11.0.0 which is scheduled to be out in about a month.

For this issue, the only current solution is to stay at yarn@1.5.1 which for some reason I don't quite understand avoids the Node bug.

@borekb
Copy link
Author

borekb commented Oct 31, 2018

Can someone try on Node 11 on Windows? nodejs/node#21943 has supposedly shipped in that version so I'm wondering if the issue is resolved (am not on Windows these days).

@patricksevat
Copy link

I just upgraded to Node 11.1.0 and executed $ yarn config set script-shell "C:\\Program Files\\Git\\bin\\bash.exe" and $ yarn config set shell "C:\\Program Files\\Git\\bin\\bash.exe" and was able to properly run a package.json script which executes mkdir -p ./foo/bar which I was not able before

@TheHalcyonSavant
Copy link

TheHalcyonSavant commented Mar 15, 2019

Thanks @patricksevat. Upgrading only to Node 11.11.0 worked for me.

@httpete
Copy link

httpete commented Mar 17, 2019

Bottom line, node 11 and latest gitbash work fine. If you use <11, it hangs threads, and generally doesn't work.

@Ragnoroct
Copy link

Just to add some extra info to anyone struggling with this and cannot downgrade yarn versions. You can switch to using cmd.exe as your shell and it should work.

I needed to clear these values for it to work

npm config delete script-shell
yarn config delete script-shell
yarn config delete shell

And set this config either by running this command or .npmrc

npm config set shell "C:\\WINDOWS\\system32\\cmd.exe"
#.npmrc in project folder or home folder
shell = "C:\\WINDOWS\\system32\\cmd.exe"

@Brunni132
Copy link

Brunni132 commented Jun 14, 2020

Seconding the

npm config delete script-shell
yarn config delete script-shell
yarn config delete shell

I don't know why but it worked for me. Previously I would get errors like this for running even a very simple task like scripts: { "test": "echo test" } in package.json.

bash: /d: No such file or directory

Also it would work with npm run script. Now with the deletion of the default shell it works under git-bash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests