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 init fails on Windows under Git bash / MinGW / Cygwin #743

Closed
lewiswalsh opened this issue Oct 11, 2016 · 30 comments
Closed

Yarn init fails on Windows under Git bash / MinGW / Cygwin #743

lewiswalsh opened this issue Oct 11, 2016 · 30 comments

Comments

@lewiswalsh
Copy link

Under Git Bash on Windows when entering 'yarn init' I get the following error:

error Can't answer a question unless a user TTY
at ConsoleReporter.question (C:\Program Files (x86)\Yarn\lib\reporters\console\console-reporter.js:189:29)
at Object. (C:\Program Files (x86)\Yarn\lib\cli\commands\init.js:91:38)
at next (native)
at step (C:\Program Files (x86)\Yarn\node_modules\babel-runtime\helpers\asyncToGenerator.js:17:30)
at C:\Program Files (x86)\Yarn\node_modules\babel-runtime\helpers\asyncToGenerator.js:28:20
at run (C:\Program Files (x86)\Yarn\node_modules\core-js\library\modules\es6.promise.js:87:22)
at C:\Program Files (x86)\Yarn\node_modules\core-js\library\modules\es6.promise.js:100:28
at flush (C:\Program Files (x86)\Yarn\node_modules\core-js\library\modules_microtask.js:18:9)
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)

Other yarn commands seem to work as expected.

Yarn v0.15.1
Node v6.0.0
Windows 10 Pro 1607

@Daniel15
Copy link
Member

Daniel15 commented Oct 11, 2016

Seems like this is an issue with Cygwin and MinGW in that they're not 'proper' TTYs: nodejs/node#3006

I don't think we can fix this at our end.

@Daniel15 Daniel15 removed the cat-bug label Oct 11, 2016
@Daniel15 Daniel15 changed the title Yarn init fails on Windows under Git bash Yarn init fails on Windows under Git bash / MinGW / Cygwin Oct 12, 2016
@oliversalzburg
Copy link

Well, one thing you could do would be to remove the check ;)

In all seriousness though. It is my understanding that the check is in place because you're trying to make sure that the I/O scenario that is about to happen will work. Does that check actually achieve this? Will the scenario actually fail in MinGW? If not, then a different check should be performed or it should be omitted completely IMHO.

@Daniel15
Copy link
Member

Daniel15 commented Oct 12, 2016

My understanding is that the check is to stop the process hanging indefinitely when not using a TTY (for example, if running as part of a build process that pipes stdin and stdout). In theory, if there's no TTY, there's no way to accept input. May be the check should "if it's a TTY or if it's MinGW" to handle this case specifically? I think that'd fail if you try to pipe the output to a file when running under MinGW though (it'd hang).

@jdalton
Copy link
Contributor

jdalton commented Oct 13, 2016

FWIW the yarn master branch works with

  • WSL
  • MINGW32
  • Git Bash
  • Cygwin

npm init works in Git Bash, Cygwin, WSL, & MINGW32.

@Daniel15
Copy link
Member

Yeah, I just noticed that npm init is fine. Sounds like we should take a look at how npm is handling it 😄

@oliversalzburg
Copy link

oliversalzburg commented Oct 19, 2016

Sounds like we should take a look at how npm is handling it

They're simply not enforcing isTTY.

@Daniel15
Copy link
Member

Ahh, that's an interesting approach @oliversalzburg. I guess it means trying to run it in a script would result in the script "freezing" as it sits waiting for user input. Not ideal 😕

Maybe we could do that just for Git Bash and Cygwin - Only check isTTY on platforms that properly support it

@oliversalzburg
Copy link

So on the one side you have the users who, for some reason, try to run a command that requires user interaction in a script, which will now fail loudly and would otherwise fail silently and on the other side you have everyone who uses a somewhat popular terminal on Windows and is unable to use the command.

I really don't see why this is a hard choice or why it would need even more complicated terminal detection code to solve. The check is counter productive and should be removed. Slapping more prone-to-error code on top is not the solution.

That being said, I really don't care one way or the other, as there are other terminal emulators that run Git Bash which are not affected by this "problem". I would suggest that everyone who runs into this should have a look at ConEmu.

@maybeec
Copy link

maybeec commented Nov 3, 2016

I also face this issue, so I run node -p -e "Boolean(process.stdout.isTTY)" on git-bash as well as on windows cmd. Both return true, which does not fit to the behavior of git-bash and cmd as discussed here, right? Or is there anything I misunderstood regarding the isTTY discussion?
If my assumption is right, this will point the finger again to Yarn.

Yarn version:
0.16.1
Node version:
4.4.5
Platform:
Win7 x64
Trace:

Error: Can't answer a question unless a user TTY
      at ConsoleReporter.question (C:\Program Files (x86)\Yarn\lib\reporters\console\console-reporter.js:186:29)```

@maybeec
Copy link

maybeec commented Nov 3, 2016

btw. same for nodejs 6.9.1

@ghost
Copy link

ghost commented Nov 16, 2016

How is this going ?
Still working on this ? I'm facing this issue at the moment.

@karlpatrickespiritu
Copy link

Hope this will be fixed soon.

@thetrompf
Copy link
Contributor

I really don't get why it fails, yarn uses the "proper" way for testing this in

return Promise.reject(new Error("Can't answer a question unless a user TTY"));

by testing for process.stdout.isTTY

I'm using minTTY which is bundled in Git for Windows along side with Git bash as well.

Node: v7.2.1
Yarn: v0.17.10
bkc@DESKTOP-NNSLT74 ~ $ node
> process.stdout.isTTY
true
>
(To exit, press ^C again or type .exit)
>
bkc@DESKTOP-NNSLT74 ~ $ cd workspace/ts-test/
bkc@DESKTOP-NNSLT74 ~/workspace/ts-test (master) $ yarn init
yarn init v0.17.10
error An unexpected error occurred: "Can't answer a question unless a user TTY".
info If you think this is a bug, please open a bug report with the information provided in "C:\\Users\\bkc\\workspace\\ts-test\\yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/init for documentation about this command.
bkc@DESKTOP-NNSLT74 ~/workspace/ts-test (master) $

@thetrompf
Copy link
Contributor

thetrompf commented Dec 12, 2016

Interestingly enough, if I install yarn as a dependency, to a project

yarn add yarn

and in invoke yarn via node and yarn.js it works fine.

node ./node_modules/yarn/bin/yarn.js init
yarn init v0.17.10
question name (yarn-test):

So it must have something to do with the native windows version?

@thetrompf
Copy link
Contributor

Now it gets really weird, if I omit the node part, and try to invoke

./node_modules/yarn/bin/yarn.js init

as an executable, it fails.

@Daniel15
Copy link
Member

Daniel15 commented Dec 13, 2016

@thetrompf

So it must have something to do with the native windows version?

It's possible - Running "yarn" on Windows actually goes through either a batch file (when using a regular terminal like cmd.exe, Cmder, etc) or a shell script (when using something Bash-based like MinGW, Cygwin, etc). If you installed to the default location, it's at C:\Program Files (x86)\Yarn\bin\yarn.cmd.

thetrompf added a commit to thetrompf/yarn that referenced this issue Dec 13, 2016
Previous fix only supported some old configuration of Git bash
provided by Git for windows, newer Git bash use standard MINGW
which uses a different `uname` but the fix is ultimately the same

Github: yarnpkg#743
Daniel15 pushed a commit that referenced this issue Dec 15, 2016
* Support interactive commands in standard MINGW as well

Previous fix only supported some old configuration of Git bash
provided by Git for windows, newer Git bash use standard MINGW
which uses a different `uname` but the fix is ultimately the same

Github: #743

* Refactor: use better variable name when determine to use winpty

* Support both MSYS 32bit and 64bit terminal emulators
@ArtistsTechGuy
Copy link

I fixed this by updating my git for windows to the latest version, it looks to be a problem with winpty.exe I also updated to the latest nightly version of yarn v0.20.0 as there was a patch concerning this applied in version 0.19.

node.js - v6.9.4 | yarn - v0.20.0-20170117.1018 | git for windows - 2.11.0.3 with MinGW teminal

@hanorine
Copy link

I second with ArtistsTechGuy, upgrading to latest versions solved the issue.

@astudio8
Copy link

Even upgrading Git to the latest version, it fails for me:

yarn init (yarn 0.24.5)
error An unexpected error occurred: "Can't answer a question unless a user TTY".

@ilatypov
Copy link

ilatypov commented May 26, 2017

Cygwin's mintty returns false to node -p -e "Boolean(process.stdout.isTTY)".

I wonder if this stalls compound scripts such as "build": "yarn run clean && yarn cover". I see a process tree with the last command stuck in the destructor of node.exe's v8::Unlocker, with our clean script defined as "clean": "rimraf ./reports",

  • ..node.exe ..yarn.js run build
    • ..cmd.exe /d /s /c yarn run clean && yarn cover
      • node ..yarn.js run clean

@rofrol
Copy link

rofrol commented May 30, 2017

I got the same error as @astudio8

$ yarn init
yarn init v0.24.5
error An unexpected error occurred: "Can't answer a question unless a user TTY".
info If you think this is a bug, please open a bug report with the information provided in "C:\\projects_personal\\react\\hyperscript-helpers-elm-like\\yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/init for documentation about this command.
$ git version
git version 2.13.0.windows.1

Windows 10

@lvlirko
Copy link

lvlirko commented Jun 28, 2017

Git Bash error ..

yarn init v0.24.6  
error An unexpected error occurred: "Can't answer a question unless a user TTY".

$ git --version 2.13.1.windows.2


Good thing is, Windows PowerShell works without errors.

@a1mersnow
Copy link

Is there any solution now?
I has been waiting for this to fix since a long time ago.

@philipjscott
Copy link

I think I have a solution. Add the following to your .bashrc file:

alias yarn='node "C:\Program Files (x86)\Yarn\bin\yarn.js"'

Running yarn init should work now, maybe, hopefully... It works on my PC, at least.

@andreysobal
Copy link

I had the same problem.
When use Git Bash under console emulator ConEmu, this problem don't arise.

@lsvidal
Copy link

lsvidal commented Sep 27, 2017

As previously stated in this thread, the problem is TTY handling in git-bash. So successfully ran 'yarn upgrade-interactive' using 'winpty yarn.CMD upgrade-interactive' and latter aliased yarn to 'winpty yarn.CMD' in .bashrc

@jmathew
Copy link

jmathew commented Sep 28, 2017

I think it's worth noting that sometimes you want winpty and sometimes you dont. Though in 90% cases you're safe with it prefixed.

From what I can tell it boils down to:

Action Such as? Prefix with winpty?
Using yarn inside a pipe? yarn.cmd --version | cat No
Using an interactive yarn command? yarn.cmd init Yes
Doing something outside a pipe and not interactive? yarn.cmd install yarn.cmd add Doesn't matter
$ winpty yarn.cmd init
yarn init v1.0.2
error An unexpected error occurred: "canceled".
info If you think this is a bug, please open a bug report with the information provided in 

$ yarn.cmd init
yarn init v1.0.2
error An unexpected error occurred: "Can't answer a question unless a user TTY".
info If you think this is a bug, please open a bug report with the information provided in 

$ winpty yarn.cmd --version
1.0.2

$ winpty yarn.cmd --version |cat
stdout is not a tty

$ yarn.cmd --version | cat
1.0.2

@thetrompf
Copy link
Contributor

@jmathew see my pull request, which tries to fix this #4577

@jmathew
Copy link

jmathew commented Sep 28, 2017

@thetrompf I haven't tested it but the script change makes sense. Thanks!

@naguibihab
Copy link

To me this was a pretty silly issue, yarn init or yarn login wouldn't work on git bash that gets installed with git for windows but they'd work on standard cmd

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

No branches or pull requests