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

[4.0.0 | Git Bash | Windows 10] stdin is not a tty #627

Closed
wKovacs64 opened this issue Jan 7, 2020 · 42 comments · Fixed by #634
Closed

[4.0.0 | Git Bash | Windows 10] stdin is not a tty #627

wKovacs64 opened this issue Jan 7, 2020 · 42 comments · Fixed by #634
Assignees
Labels

Comments

@wKovacs64
Copy link

Husky 4.0.0 isn't working in Git Bash for Windows 10, triggering a stdin is not a tty error for every git operation that triggers a hook.

Versions

OS: Windows 10 1903
Shell: Git Bash (GNU bash, version 4.4.23(1)-release (x86_64-pc-msys))
Git: git 2.24.1.windows.2

HUSKY_DEBUG=1 npm install husky --save-dev

$ HUSKY_DEBUG=1 npm install husky --save-dev

> husky@4.0.0 install C:\dev\test\husky4-tty-test\node_modules\husky
> node husky install

husky > Setting up git hooks
husky:debug Current working directory is C:\dev\test\husky4-tty-test\node_modules\husky
husky:debug INIT_CWD is set to C:\dev\test\husky4-tty-test
husky:debug Git rev-parse command returned:
husky:debug   --git-common-dir: undefined
husky:debug   --show-prefix:
The "path" argument must be of type string. Received type undefined
husky:debug TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
    at validateString (internal/validators.js:112:11)
    at Object.resolve (path.js:139:9)
    at getDirs (C:\dev\test\husky4-tty-test\node_modules\husky\lib\installer\bin.js:27:49)
    at run (C:\dev\test\husky4-tty-test\node_modules\husky\lib\installer\bin.js:62:62)
    at Object.<anonymous> (C:\dev\test\husky4-tty-test\node_modules\husky\lib\installer\bin.js:85:1)
    at Module._compile (internal/modules/cjs/loader.js:959:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Function.Module._load (internal/modules/cjs/loader.js:727:14)
    at Module.require (internal/modules/cjs/loader.js:852:19)
husky > Failed to install

> husky@4.0.0 postinstall C:\dev\test\husky4-tty-test\node_modules\husky
> opencollective-postinstall || exit 0

Thank you for using husky!
If you rely on this package, please consider supporting our open collective:
> https://opencollective.com/husky/donate

npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN husky4-tty-test@1.0.0 No description
npm WARN husky4-tty-test@1.0.0 No repository field.

+ husky@4.0.0
added 48 packages from 22 contributors and audited 48 packages in 2.047s

3 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

HUSKY_DEBUG=1 git commit

Note: on the fresh test repo, this command worked because the first command failed so the hooks did not install properly. On an existing repo with existing hooks, it looks like this:

husky:debug husky v4.0.0 (created at 1/7/2020, 1:24:18 PM)
husky:debug pre-commit hook started
husky:debug Current working directory is /c/dev/test/existing-repo
husky:debug pre-commit hook started
stdin is not a tty
husky:debug yarn husky-run exited with 1 exit code
@wKovacs64
Copy link
Author

Adding exec < /dev/tty to ~/.huskyrc as mentioned in several other similar issues gets around the problem but I didn't see anything about it in the change log and suspect it shouldn't be required based on those other discussions.

@typicode typicode added the bug label Jan 8, 2020
@typicode
Copy link
Owner

typicode commented Jan 8, 2020

Thanks again for the report.

I've been able to reproduce the first issue by creating a non git project:

$ mkdir foo && cd foo
$ npm init -y && npm install husky
# ...
husky > Setting up git hooks
The "path" argument must be of type string. Received type undefined
husky > Failed to install

Husky should have displayed a better error message.

Running git init or cloning an existing project should fix the issue.

$ mkdir foo && cd foo
$ git init && npm init -y && npm install husky

That said, I have trouble reproducing the one with stdin is not a tty. Could you provide some steps with a freshly created repo?

I've tried this in Git Bash on Windows 10:

$ mkdir foo && cd foo
$ git --version && npm --version
git version 2.24.1.windows.2
6.13.4
$ git init && npm init -y && npm i husky -D
$ echo '{ "hooks": { "pre-commit": "echo hello && exit 1" } }' > .huskyrc
$ git add .huskyrc && git commit -m foo
husky > pre-commit (node v10.10.0)
hello

@wKovacs64
Copy link
Author

Thanks for investigating. Seems to be an issue pertaining to yarn only (npm works, as you mentioned).

Replace npm i husky -D with yarn add husky -D (or even run the yarn one after the npm one if you want) and it will start producing the stdin is not a tty error.

Comparing .git/hooks/pre-commit, this is the only meaningful difference I see:

-packageManager=npm
+packageManager=yarn

@typicode
Copy link
Owner

typicode commented Jan 8, 2020

Hmm, I've done the previous steps but used yarn 1.21.1 and I'm not getting stdin is not a tty error. What's the content of your .huskyrc?

@wKovacs64
Copy link
Author

In real projects, I'm using husky.config.js:

module.exports = {
  hooks: {
    'commit-msg': 'commitlint -E HUSKY_GIT_PARAMS',
    'pre-commit': 'lint-staged',
  },
};

But I reproduced it using your example steps, so .huskyrc is just:

{ "hooks": { "pre-commit": "echo hello && exit 1" } }

@jetersen
Copy link
Contributor

jetersen commented Jan 8, 2020

this is not limited to git bash, this happens in command prompt and powershell.

For me I only experienced it on git push

@wKovacs64
Copy link
Author

Hmm, it only happens to me in Git Bash and it's any/all hooks. Works as expected in PS and CMD.

@typicode
Copy link
Owner

typicode commented Jan 9, 2020

What's your version of yarn?

@wKovacs64
Copy link
Author

$ yarn --version
1.21.1

@jetersen
Copy link
Contributor

jetersen commented Jan 9, 2020

❯ yarn -v
1.21.1

@typicode
Copy link
Owner

typicode commented Jan 9, 2020

The first issue (The "path" argument must be of type string.) should be fixed by Husky 4.0.3 and a better error should be displayed.

I'm still trying to reproduce the stdin error but I don't see yet what would be the difference between my env and yours 🤔

screen

@jetersen
Copy link
Contributor

jetersen commented Jan 9, 2020

Seems it's related to eslint in my case:

× eslint --fix found some errors. Please fix them and try committing again.


Oops! Something went wrong! :(

ESLint: 6.8.0.

ESLint couldn't find the config "xo-space/esnext" to extend from. Please check that the name of the config is correct.  
The config "xo-space/esnext" was referenced from the config file in "C:\git\code\release-drafter
ode_modules\husky\.eslintrc.js".

If you still have problems, please stop by https://gitter.im/eslint/eslint to chat with the team.
husky > pre-commit hook failed (add --no-verify to bypass)

Seems like you should limit what get's published in your npm package.

@wKovacs64
Copy link
Author

image

🤷‍♂

You're sure you don't have exec < /dev/tty in your ~/.huskyrc or anything like that, @typicode?

@typicode
Copy link
Owner

typicode commented Jan 9, 2020

Good idea. But no, just checked :/ (I don't have a ~/.huskyrc). There are threads about Yarn and stdin is not a tty error on Windows 10, maybe that can help.

Do you also have this error if you try in a fresh repo with Yarn 2:
https://next.yarnpkg.com/

You just have to run yarn policies set-version berry before installing Husky.

@wKovacs64
Copy link
Author

Those threads are how I found exec < /dev/tty, which is the only thing has worked so far. But that shouldn't be necessary, right? I didn't need it in husky v3.1.0, anyway. 😕 If that's the solution, so be it - it's just new and I'm not familiar with the repercussions in other areas of the system (maybe there are none).

Interestingly, the error does not occur with yarn v2.0.0-rc.21 (berry).

@viceice
Copy link

viceice commented Jan 9, 2020

Seeing this on git push too

❯ git push -f
stdin is not a tty

Roleback to 3.1.0 as workaround

@justinhp
Copy link

justinhp commented Jan 9, 2020

I too saw this on git push from a Windows 10 machine using Git v2.20.1.windows.1 and Yarn v1.21.1. Downgrading to 3.1.0 fixed the issue.

@jetersen
Copy link
Contributor

jetersen commented Jan 9, 2020

@viceice @justinhp if you update husky to v4.0.4 do you get any additional information?

@jetersen
Copy link
Contributor

jetersen commented Jan 9, 2020

for me v4.0.4 still fails and seems to be related to yarn v1.21.1
if I go into pre-push hook shell script and change packageManager=yarn to packageManager=npm it I can suddenly git push again.

@jetersen
Copy link
Contributor

jetersen commented Jan 10, 2020

after enough investigating it seems to me that this is bug located inside the yarn v1's shell script using winpty

I created two PRs,
first one solve winpty problem if you still wish to use yarn run
and second one uses npx instead of yarn run

should be noted that the first one is dependent on which version of yarn your using.
So it might need some additional logic

@typicode
Copy link
Owner

Thanks for the PRs!

@viceice
Copy link

viceice commented Jan 10, 2020

Strange, pre-commit works, but pre-push not.

❯ git push origin feature/maintenance
husky:debug husky v4.0.6 (created at 2020-1-10 9:40:27)
husky:debug pre-push hook started
husky:debug Current working directory is ~/projects/test
husky:debug pre-push hook started
stdin is not a tty
husky:debug yarn run --silent husky-run exited with 1 exit code
error: failed to push some refs to 'https://******/scm/test.git'

@tobiasweibel
Copy link

If I run npx husky then the git commands are working again. It's of course a workaround.

@viceice
Copy link

viceice commented Jan 10, 2020

exec < /dev/tty does work for normal cmd /powershell, but crashes git commit in vscode (/dev/tty No such a device or address)

@viceice
Copy link

viceice commented Jan 10, 2020

ok, this does the trick:

if [ -t 1 ]; then
  exec < /dev/tty
fi

@jetersen
Copy link
Contributor

jetersen commented Jan 10, 2020

what does -t 1 validate?

@viceice
Copy link

viceice commented Jan 10, 2020

what does -t 1 validate?

It will test if we stdout is available.

https://stackoverflow.com/questions/911168/how-to-detect-if-my-shell-script-is-running-through-a-pipe

@typicode typicode self-assigned this Jan 11, 2020
@typicode
Copy link
Owner

@Casz @wKovacs64 @viceice I'd really like to be able to test locally. Working or reviewing PRs related to stdin error without a reproducible example is quite hard.

Would you have any ideas what I could do to have the error in my env? I've installed Git using https://git-scm.com/ with default options (tried to reinstall it also multiple times) and Yarn using npm i -g yarn. I tried on another computer with Windows 10 and couldn't reproduce either.

@typicode typicode reopened this Jan 14, 2020
@typicode
Copy link
Owner

typicode commented Jan 14, 2020

Found it, installed Yarn using the Windows installer (https://yarnpkg.com/en/docs/install#windows-stable) and it fails with stdin is not a tty 🎉

@viceice
Copy link

viceice commented Jan 14, 2020

I installed git, nodejs-lts and yarn with chocolatey.

git: 2.24.1.windows.2
yarn: 1.21.1
node: 12.14.1

@jetersen
Copy link
Contributor

I installed with chocoloately and had the issue.

@jetersen
Copy link
Contributor

Let me add a PR with reproducible tests inside appveyor. :)

filipesilva added a commit to filipesilva/angular-cli that referenced this issue Jan 16, 2020
Husky was failing on push due to typicode/husky#627.
filipesilva added a commit to filipesilva/angular-cli that referenced this issue Jan 16, 2020
Husky was failing on push due to typicode/husky#627.
mgechev pushed a commit to angular/angular-cli that referenced this issue Jan 16, 2020
Husky was failing on push due to typicode/husky#627.
dgp1130 pushed a commit to dgp1130/angular-cli that referenced this issue Jan 21, 2020
Husky was failing on push due to typicode/husky#627.

(cherry picked from commit 3eaa881)
dgp1130 pushed a commit to angular/angular-cli that referenced this issue Jan 21, 2020
Husky was failing on push due to typicode/husky#627.

(cherry picked from commit 3eaa881)
@Sowed
Copy link

Sowed commented Feb 24, 2020

If I run npx husky then the git commands are working again. It's of course a workaround.

@tobiasweibel Works like a charm! Thank. Just curious though, how is it working? Restarting the PC resets the env and the workaround ceases to work. I guess it's to do with how npx works.

@smakhtin
Copy link

smakhtin commented Mar 23, 2020

Same for us, using workarounds mentioned above.

@viceice
Copy link

viceice commented Apr 9, 2020

@jetersen Any timeframe to get this solved?

@tobiasweibel
Copy link

I think the problem was fixed already a longer time ago. Just update to the latest 4* version.

@viceice
Copy link

viceice commented Apr 9, 2020

ok, seems to work 😅 will remove the workaround

@mgdeveloper79
Copy link

mgdeveloper79 commented Jul 30, 2020

I had the same issue with version 3.x but version 4.1.0 has worked for me without needing any workarounds mentioned above.

@oarthursilva
Copy link

ok, this does the trick:

if [ -t 1 ]; then
  exec < /dev/tty
fi

thx viceice, it worked smoothly in windows 10

@enzo-phinx
Copy link

ok, this does the trick:

if [ -t 1 ]; then
  exec < /dev/tty
fi

thx viceice, it worked smoothly in windows 10

This worked for me.

@codeyourwayup
Copy link

Windows 11, bash.
step1: cd ~
step2: $ touch .huskyrc
step3: nano .huskyrc
step4: paste

if [ -t 1 ]; then
  exec < /dev/tty
fi

step5: ctrl+x to save
Success!!

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

Successfully merging a pull request may close this issue.