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

Lefthook doesn't find executables with Desktop Git Client - npx: not found #887

Open
bennycode opened this issue Dec 6, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@bennycode
Copy link

🔧 Summary

When I try to push with my Git Desktop client (SmartGit) then lefthook doesn't find npx. If I push from within VS Code, it works.

Here is my lefthook.yml:

pre-commit:
  parallel: true
  commands:
    format:
      glob: '*.{css,html,json,less,md,scss,yml}'
      run: npx -c "cross-env NODE_OPTIONS=--max_old_space_size=4096 prettier --write --log-level error {staged_files}"
    lint:
      glob: '*.{js,jsx,ts,tsx}'
      run: npx eslint {staged_files} --fix

Lefthook version

v1.9.0

Steps to reproduce

  • Use a Git Desktop client (like SmartGit)
  • Use nvm to install and run Node.js

Expected results

Lefthook finding npx and other tools

Actual results

Lefthook failing to find npx:

\u2503 lint \u276f
sh: 1: npx: not found
exit status 127\u2503 format \u276f
sh: 1: npx: not found
exit status 127

Possible Solution

@bennycode bennycode added the bug Something isn't working label Dec 6, 2024
@mrexox
Copy link
Member

mrexox commented Dec 6, 2024

@bennycode , do you start VSCode from terminal? It's surprising that it works without any extra configuration.

Lefthook inherits envs from the environment it was called from. If it's your terminal, you usually have all envs, but with a desktop app you probably miss some PATH adjustments.

Please, use rc option if you use some desktop app with lefthook (you can put it to lefthook-local.yml, see examples)

Fast fix: add a rc file with the line export PATH=$PATH:<path where npx lives>

which npx

But better solution is to repeat your shell rc file adjustments.

@bennycode
Copy link
Author

Hi @mrexox and thank you for your fast feedback. It helped me to narrow down the problem...

I am using Windows 11 and the Windows Subsystem for Linux. My SmartGit is installed in the WSL as it supports GUI applications. There is indeed a difference in how I can start my SmartGit desktop client...

Starting from Start Menu

image

If I run SmartGit from the Windows start menu, then the commit in combination with Lefthook fails as it cannot find npx:

sh: 1: npx: not found

Starting from Ubuntu App (Terminal)

image

When I initially launch my terminal using the Ubuntu app on Windows and run SmartGit (~/smartgit/bin/smartgit.sh), I don't encounter any issues with Lefthook. However, it seems that Lefthook is not executed at all on a pre-commit.

Actually, when committing through VS Code (launched from my Start menu), the pre-commit hook is not executed either.

@mrexox
Copy link
Member

mrexox commented Dec 9, 2024

I see. Well, in this case I can suggest you to install lefthook via winget, so it is available from anywhere (does it work for Winget like this?).

This is the first time I meet your use case and it's interesting if installation via winget can fix this.

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

No branches or pull requests

2 participants