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

Can't add a hook #1043

Closed
1 task done
thany opened this issue Sep 13, 2021 · 10 comments
Closed
1 task done

Can't add a hook #1043

thany opened this issue Sep 13, 2021 · 10 comments

Comments

@thany
Copy link

thany commented Sep 13, 2021

Troubleshoot

If you're migrating from husky 4, see:
https://typicode.github.io/husky/#/?id=migrate-from-v4-to-v7

Context
I'm using Husky in the command prompt.

Here's what I do:

npx husky add .husky/pre-push "npm run prepush"

Also tried with single-quotes, as per the documentation. Both don't work.

Output:

Usage:
  husky install [dir] (default: .husky)
  husky uninstall
  husky set|add <file> [cmd]

Errrr, that's what I'm doing, aren't I? 🤨
What does it want me to do instead?! No, I'm calling this a bug. I'm doing exactly as the usage instructs me to do, and I can literally copypaste from the documentation and it still won't work:

> npx husky add .husky/commit-msg 'npx --no-install commitlint --edit "$1"'
Usage:
  husky install [dir] (default: .husky)
  husky uninstall
  husky set|add <file> [cmd]

Sorry mates, but this is not okay. How did this get past testing?

It used to be so simple in Husky v4... Just add a thing in the package.json, and done. Worked everytime, everywhere. I wonder why you had to make everything difficult and unreliable... This is not the first problem I've run into that's new in v7 😑

Please give your huskies, and Husky, some more love 😘

@yiidot
Copy link

yiidot commented Sep 13, 2021

Got the same issue, emm.
You can try this temporarily:

npx husky add .husky/pre-push "npm-run-prepush"

and then change "npm-run-prepush" to "npm run prepush".
It works in my project.

@typicode
Copy link
Owner

If you're on Windows, it's an issue with npx.
You can do node node_modules/.bin/husky add ... instead.

@thany
Copy link
Author

thany commented Sep 13, 2021

@yiidot

npx husky add .husky/pre-push "npm-run-prepush"

Huh, weird. That works. Thanks.

@typicode

If you're on Windows, it's an issue with npx.

Are you sure? I've executed other npx commands just fine. Can you workaround it?

@typicode
Copy link
Owner

Pretty sure. As a quick test, you can add console.log('argv =', process.argv) at line 2 of node_modules/husky/lib/bin.js and run npx husky add .husky/commit-msg 'npx --no-install commitlint --edit "$1"'.

If I remember correctly, you can then run the same command with node node_modules/.bin/husky add ... and you should get a different output.

No workaround possible at husky level.

There's probably a tricky parsing issue related to Windows and rn I don't have the time to create a proper issue on npm repo.

Duplicate #1010

I've updated docs BTW.

@luisenricke
Copy link

If I remember correctly, you can then run the same command with node node_modules/.bin/husky add ... and you should get a different output.

This solution works in WSL too, thanks.

@stale
Copy link

stale bot commented Nov 22, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Nov 22, 2021
@thany
Copy link
Author

thany commented Nov 23, 2021

Beep boop, bad bot!

We only got a workaround. I haven't seen a solution yet.

/edit Thanks, good bot 😊

@stale stale bot removed the wontfix label Nov 23, 2021
@melvingaye
Copy link

It's definitely a windows npx issue. Use yarn as a workaround

@thany
Copy link
Author

thany commented Jan 17, 2022

I'm not going to install yarn for this. First off, our project doesn't use yarn. Secondly, Husky should just work with whatever NPM versions come with the Node.js versions that are officially supported.

The real fix is in Husky to properly find its directories, or fix whatever else is going wrong. Not being able to "see" the .husky directory, for example, is entirely fixable by looking for it in the right place.

Or fix it by requiring a very specific NPM version (not recommended as one is not always in control of this, for example when using NVM).

@typicode
Copy link
Owner

Seems to be fixed in npm 8.1.1

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

No branches or pull requests

5 participants