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

[Windows] [lint-staged] [GitHub Desktop] .husky/pre-commit script is unable to find npx #1292

Open
1 task done
trusktr opened this issue Aug 2, 2023 · 2 comments
Open
1 task done

Comments

@trusktr
Copy link

trusktr commented Aug 2, 2023

Troubleshoot

Context

Please describe your issue and provide some context:

  • Terminal or GUI client (PowerShell, Git Bash, GitHub Desktop, ...) GitHub Desktop
  • If applicable, content of the failing hook:
    #!/usr/bin/env sh
    . "$(dirname -- "$0")/_/husky.sh"
    
    npx lint-staged
  • If possible, minimal steps to reproduce the issue
    • There are no minimal steps for Windows (f.e. install Node.js, try a lot of things, hope it works, end with a workaround, then don't go back and figure it all out again).

Error:

/bin/bash: D:/Program Files (x86)/nodejs/npx: No such file or directory
husky - pre-commit hook exited with code 127 (error)
husky - command not found in PATH=...

However I can git commit just fine in PowerShell or CMD, and it runs the hooks. I can see npx and other commands in my Path.

I get this issue when trying to commit in GitHub Desktop.

Workaround:

Using the direct path to the executable without npx solved the issue for now:

#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

./node_modules/.bin/lint-staged

Thank you!

@KonkretneKosteczki
Copy link

KonkretneKosteczki commented Oct 27, 2023

It may be a little strange workaround, but in the end we have to run it via a package manager only because node_modules/.bin is not added to the path so husky cannot find the relevant commands.

If you were to manually modify the path it would work just fine without it.

#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

export PATH="$PATH:./node_modules/.bin"
lint-staged --debug

Works with nested projects as well, just modify the path to node_modules since it's run from the top level directory.

I prefer this method over yours, since lint-staged might run other scripts that will also be unrecognized by husky otherwise.

@timi137137
Copy link

Is there any solution to this problem? Please help me (without changing the PATH)

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

3 participants