Skip to content

Git pre-commit hook fails to run because of "No such file or directory" #12586

Closed

Description

@saschanaz

Describe the bug

I have a .git/hooks/pre-commit which is exactly the following:

#!/bin/sh
npm test

When I commit via GitHub Desktop, it fails:

/bin/bash: C:/Program Files/nodejs/npm: No such file or directory

It works when committing via git CLI.

Version & OS

Open 'About GitHub Desktop' menu to see the Desktop version. Also include what operating system you are using.

Steps to reproduce the behavior

  1. Create a hook as .git/hooks/pre-commit
  2. Commit something
  3. See error

Expected behavior

It should run the npm command

Actual behavior

It says no such file

Screenshots

image

Logs

2021-07-09T14:34:12.623Z - info: [ui] [Timing] Action 'create commit' for 'saschanaz/types-web' took 0.292s
2021-07-09T14:35:53.954Z - info: [ui] Executing createCommit: git commit -F - (took 1.372s)
2021-07-09T14:35:53.963Z - error: [ui] `git commit -F -` exited with an unexpected code: 1.
stderr:
/bin/bash: C:/Program Files/nodejs/npm: No such file or directory

Additional context

This had been working but is regressed since a few months ago.

Pinned by niik

Activity

  1. steveward commented on Jul 27, 2021

    @steveward
    Contributor

    @saschanaz thanks for the report. I tested this out in a Windows VM and was unable to reproduce this, so my guess is it's something specific to your environment. Can you try launching GitHub Desktop via the command line using the github command and see if that resolves this issue?

  2. added
    more-info-needed
    on Jul 27, 2021
  3. saschanaz commented on Jul 27, 2021

    @saschanaz
    ContributorAuthor

    Can you try launching GitHub Desktop via the command line using the github command and see if that resolves this issue?

    No, that does not solve the issue, the same message opens when committing anything.

  4. removed
    more-info-needed
    on Jul 27, 2021
  5. ruggi99 commented on Aug 3, 2021

    @ruggi99
    Contributor

    @saschanaz Have you installed a node version manager in your environment?
    I have the same issue and I'm trying to tackle it down

  6. saschanaz commented on Aug 3, 2021

    @saschanaz
    ContributorAuthor

    No, but winget should probably work for that purpose I guess.

  7. ruggi99 commented on Aug 3, 2021

    @ruggi99
    Contributor

    Nevermind.
    I have the same issue, like already reported in #11603

  8. saschanaz commented on Aug 3, 2021

    @saschanaz
    ContributorAuthor

    I don't think it's the same issue if your issue has symlink involved.

  9. ruggi99 commented on Aug 3, 2021

    @ruggi99
    Contributor

    Yeah could be, or could be related for some reason

  10. ruggi99 commented on Aug 4, 2021

    @ruggi99
    Contributor

    Symlinks was an idea.
    I tried changing npm to npm.cmd (supposing you are on Windows) and got it working finally.
    Don't know why but it works. But the problem is that pre-commit hook will not be cross-platform anymore
    Does it work for you too?

  11. tomiGoljevscek commented on Nov 17, 2021

    @tomiGoljevscek

    I tried changing npm to npm.cmd

    This worked for me, thank you so much!

  12. Airkro commented on Jan 7, 2022

    @Airkro

    I think this is the same problem as #12562.

  13. Wangyaqi commented on Aug 23, 2022

    @Wangyaqi

    Insert git bin to PATH and put it before "%SystemRoot%\system32".

    It works for me. It looks like Github Desktop used the wrong bash command which was provided by wsl.

  14. WellingtonOstemberg commented on Nov 8, 2022

    @WellingtonOstemberg

    Solved my problem!
    Finally

  15. murugan1993 commented on May 8, 2023

    @murugan1993

    missing Change-Id in commit message footer this my error what to do can you explain

  16. rdrinovec commented on Jul 5, 2023

    @rdrinovec

    Insert git bin to PATH and put it before "%SystemRoot%\system32".

    It works for me. It looks like Github Desktop used the wrong bash command which was provided by wsl.

    Does not work for me 😢

  17. lucasnguyen3979 commented on Nov 22, 2023

    @lucasnguyen3979

    Insert git bin to PATH and put it before "%SystemRoot%\system32".

    It works for me. It looks like Github Desktop used the wrong bash command which was provided by wsl.

    Does not work for me 😢

    At first it didn't work for me, but then I added C:\Program Files\Git\bin to Path for both variable types: User and System, and it worked.

  18. TheMikeyRoss commented on Jun 3, 2024

    @TheMikeyRoss

    2 years later, the same problem is happening. And updating the PATH doesn't fix it

  19. rmckr commented on Jun 4, 2024

    @rmckr

    2 years later, the same problem is happening. And updating the PATH doesn't fix it

    The weird thing is, I just recently set up husky, ran into this issue, got it fixed by adding C: \Program Files\Git\bin to PATH until it broke on me again just a few days ago. I obviously did not change the PATH.

    Maybe a newer version of GitHub Desktop broke things? (I'm currently on version 3.4.0 (x64)) It looks like the Windows PATH is not respected at all, as the error message I'm getting from husky looks like it's using MinGW:

    .husky/commit-msg: line 4: npx.cmd: command not found
    husky - commit-msg script failed (code 127)
    husky - command not found in PATH=/mingw64/libexec/git-core:/mingw64/bin:/usr/bin:/c/Users/[my username]/bin:/mingw64/bin:/mingw64/usr/bin:undefined
    
  20. TheMikeyRoss commented on Jun 4, 2024

    @TheMikeyRoss

    @MeridianGH apparently something changed in Github Desktop in v3.4.0 that cause git hooks issues. It's being tracked in #18739

  21. rmckr commented on Jun 4, 2024

    @rmckr

    @MeridianGH apparently something changed in Github Desktop in v3.4.0 that cause git hooks issues. It's being tracked in #18739

    Thanks a lot, that is definitely the problem. I will hook into that issue then.

  22. R-Mohammed-Hasan commented on Jun 6, 2024

    @R-Mohammed-Hasan

    Github desktop formats files after committting precommit

    I am facing an issue where precommit format command works after committing the files. I mean the files are getting formatted only after committing the files. So I need to commit 2 times it seems...

  23. jflemingframe commented on Jul 3, 2024

    @jflemingframe

    for me C:\ProgramData\nvm was in my PATH, and messed this up.

  24. niik commented on Jan 14, 2026

    @niik
    Member

    Yesterday we shipped GitHub Desktop 3.5.5-beta1 to our beta channel with improved support for hooks related to committing.

    Screenshot showing the GitHub Desktop commit form as a pre-commit hook is running

    The support is experimental and currently limited to our beta channel. While we believe that this release resolved this issue we're looking for real-world feedback so if you have the ability we'd appreciate it if you could download our beta channel and give it a spin. Ensure the experimental hooks support it's enabled by going to Settings -> Git -> Hooks and making sure the "Load Git hook environment variables from shell" is ticked.

    Screenshot showing the hook settings dialog
  25. added 3 commits that reference this issue on Jan 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions