Closed wKovacs64 closed 3 years ago
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.
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
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
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
?
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" } }
this is not limited to git bash, this happens in command prompt and powershell.
For me I only experienced it on git push
Hmm, it only happens to me in Git Bash and it's any/all hooks. Works as expected in PS and CMD.
What's your version of yarn?
$ yarn --version
1.21.1
β― yarn -v
1.21.1
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 π€
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.
π€·ββ
You're sure you don't have exec < /dev/tty
in your ~/.huskyrc
or anything like that, @typicode?
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.
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).
Seeing this on git push
too
β― git push -f
stdin is not a tty
Roleback to 3.1.0 as workaround
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.
@ViceIce @justinhp if you update husky to v4.0.4 do you get any additional information?
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.
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
Thanks for the PRs!
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'
If I run npx husky
then the git commands are working again. It's of course a workaround.
exec < /dev/tty
does work for normal cmd /powershell, but crashes git commit in vscode (/dev/tty
No such a device or address)
ok, this does the trick:
if [ -t 1 ]; then
exec < /dev/tty
fi
what does -t 1
validate?
Tested and validated #634 feel free to review it :)
what does
-t 1
validate?
It will test if we stdout is available.
@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.
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
π
I installed git
, nodejs-lts
and yarn
with chocolatey.
git: 2.24.1.windows.2 yarn: 1.21.1 node: 12.14.1
I installed with chocoloately and had the issue.
Let me add a PR with reproducible tests inside appveyor. :)
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.
Same for us, using workarounds mentioned above.
@jetersen Any timeframe to get this solved?
I think the problem was fixed already a longer time ago. Just update to the latest 4* version.
ok, seems to work π will remove the workaround
I had the same issue with version 3.x but version 4.1.0 has worked for me without needing any workarounds mentioned above.
ok, this does the trick:
if [ -t 1 ]; then exec < /dev/tty fi
thx viceice
, it worked smoothly in windows 10
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.
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!!
Still running into this issue on husky 8.0.3 and yarn 1.22.22.
Fortunately the above fix in the .huskyrc still fixes it.
I'm getting the stdin is not a tty
error (Windows 10, PowerShell, Yarn v1.22.22) with husky v8.0.3, but no error with husky v9.0.11. π
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 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: