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

[rush] "rush setup" does not work on Windows when using Git bash #3217

Closed
octogonz opened this issue Feb 8, 2022 · 5 comments · Fixed by #3219
Closed

[rush] "rush setup" does not work on Windows when using Git bash #3217

octogonz opened this issue Feb 8, 2022 · 5 comments · Fixed by #3219
Labels
bug Something isn't working as intended

Comments

@octogonz
Copy link
Collaborator

octogonz commented Feb 8, 2022

Summary

When rush setup tries to display interactive input prompts, it works fine with Windows Command Prompt (cmd.exe) but not with Git Bash.

Repro steps

  1. Set up a repo where rush setup will prompt for input.

  2. Open Windows Command Prompt and do rush setup. It correctly prints something like this:

    Starting "rush --debug setup"
    
    NPM credentials are missing or expired
    
    ==> Fix this problem now? (y/N) _
    
  3. Now try rush --debug setup under Git Bash. It prints:

    NPM credentials are missing or expired
    
    
    ERROR: this.stdin.setRawMode is not a function
    
    TypeError: this.stdin.setRawMode is not a function
        at YesNoKeyboardLoop._uncaptureInput (C:\Users\Owner\.rush\node-v14.17.0\rush-5.59.2\node_modules\@microsoft\rush-lib\lib\logic\setup\KeyboardLoop.js:69:20)
        at YesNoKeyboardLoop.startAsync (C:\Users\Owner\.rush\node-v14.17.0\rush-5.59.2\node_modules\@microsoft\rush-lib\lib\logic\setup\KeyboardLoop.js:97:18)
    

Standard questions

Please answer these questions to help us investigate your issue more quickly:

Question Answer
@microsoft/rush globally installed version? 5.59.2
rushVersion from rush.json? 5.59.2
useWorkspaces from rush.json? true
Operating system? This issue only affects Windows-OS
Would you consider contributing a PR? Yes
Node.js version (node -v)? 14.17.0

UPDATE: Originally I thought that PowerShell was not working, but it works fine. This issue only affects Git Bash.

@octogonz octogonz added the bug Something isn't working as intended label Feb 8, 2022
@octogonz
Copy link
Collaborator Author

octogonz commented Feb 8, 2022

For Git Bash, if you invoke node lib/start.js then the prompts work fine. Whereas when invoked via the @microsoft/rush/bin/rush NPM shell command, then it fails because process.stdin.isTTY == false. Something about Git Bash causes the TTY context to get lost.

People commonly work around that by skipping the setRawMode() call, but this results in a broken UI where keyboard characters get echoed.

The technique of force-stdin-tty does fix Git Bash, though, so that's one way to solve this.

@octogonz octogonz changed the title [rush] "rush setup" does not work on Windows when using Git bash or PowerShell [rush] "rush setup" does not work on Windows when using Git bash Feb 8, 2022
@octogonz
Copy link
Collaborator Author

octogonz commented Feb 8, 2022

The technique of force-stdin-tty does fix Git Bash, though, so that's one way to solve this.

Actually I think I misunderstood something. force-stdin-tty does not seem to work, because Git Bash invokes Rush using a node.exe that was not built for MinGW, so its fs wrapper cannot access the Unix devices (ENOENT: no such file or directory, open '/dev/tty').

Other possible solutions:

  • Git Bash includes a helper called winpty that redirects Cmd.exe ports to the Unix terminal. Invoking Rush as winpty rush.cmd --debug setup solves the problem. (But interestingly winpty rush --debug setup does NOT work, even though it's invoking a Bash script.)
  • Another solution is to bypass the shell and invoke Node.js directly: node /c/Program\ Files/nodejs/node_modules/@microsoft/rush/lib/start.js --debug setup
  • People encountered this issue with Git hook scripts that prompt for TTY input using Node.js, and they solved it using < /dev/tty, but I couldn't get that to work.

@octogonz
Copy link
Collaborator Author

octogonz commented Feb 8, 2022

Yarn's upgrade-interactive command also encounters this problem:

$ yarn upgrade-interactive
Error: Raw mode is not supported on the current process.stdin, which Ink uses as input stream by default.
Read about how to prevent this error on https://github.com/vadimdemedes/ink/#israwmodesupported
    at H3.handleSetRawMode (C:\test\.yarn\plugins\@yarnpkg\plugin-interactive-tools.cjs:285:1593)

@octogonz
Copy link
Collaborator Author

octogonz commented Feb 8, 2022

This also arises with Docker, and docker/for-win#1588 (comment) observes that:

Just share a tip for Git Bash for Windows,

"Git Bash for Windows" ships with two bash program.

  • a GUI program "C:\Program Files\Git\git-bash.exe" (see right picture), called Git Bash, it does not provide tty.
  • a CUI program "C:\Program Files\Git\bin\bash.exe" (see left picture), it works perfect.

image

The difference is that git-bash.exe creates a Unixy terminal using mintty.exe, and that is what requires the winpty adapter. Whereas bash.exe reuses the Windows Terminal of cmd.exe (with Windows fonts), which node.exe can access without any adapter.

So another nice workaround is to right-click drag+drop bash.exe onto your Windows desktop to make a shortcut icon that launches bash.exe instead of git-bash.exe. Given all these problems, I wonder why the Git installer does not provide such an icon. (?)

@octogonz
Copy link
Collaborator Author

octogonz commented Feb 9, 2022

Fixed in PR #3219

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working as intended
Projects
None yet
1 participant