Yarn: `yarn run` doesn't work in Git Bash due to strange path modification

Created on 23 Apr 2018  路  17Comments  路  Source: yarnpkg/yarn

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.

triaged

Most helpful comment

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

All 17 comments

/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

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

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

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...

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

Also confirming @KatieMFritz's issue.

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

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).

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.

Has anyone tried this with Yarn 1.9.2?

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

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 [email protected] (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: https://github.com/nodejs/node/pull/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 [email protected] which for some reason I don't quite understand avoids the Node bug.

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

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

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

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

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"

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.

Was this page helpful?
0 / 5 - 0 ratings