Skip to content

Desktop fails to run pre-commit hooks on node 16+ #12562

Closed

Description

@ImRodry

Describe the bug

On Windows systems with WSL installed, GitHub desktop will run pre-commit scripts on WSL instead of running them in PowerShell regardless of which shell the user has picked to use. This results in the scripts looking for windows locations that don't exist on WSL.

Version & OS

Version 2.9.0 on Windows 10 21H1 build 19043.1081 running with WSL 2 on Ubuntu 20.04

Steps to reproduce the behavior

  1. Make some changes to a file in a project with a pre-commit script (I'm using the npm package husky which installs these)
  2. Add a commit message and try to commit
  3. You should get the following error

Expected behavior

GitHub desktop runs the pre-commit scripts on windows PowerShell, just like git does (tested this)

Actual behavior

The scripts are run on WSL which causes errors

Screenshots

image
(this path is correct for my system but may be different on others)

Logs

This log has the error multiple times, which should help.
2021-07-03.desktop.production.log

Additional context

Got this error on the repositories discordjs/discord.js and discordjs/builders (forks of them) so you can try committing on these to see if you get the same errors. I also believe this issue should have relatively high priority since I am incapable of committing through my PC (unless I use git, which is more limited on some things and harder for me)

Pinned by niik

Activity

  1. added
    windows
    on Aug 23, 2021
  2. steveward commented on Sep 9, 2021

    @steveward
    Contributor

    @ImRodry thanks for reporting this. GitHub Desktop ships with an internal version of Git which we use for all actions inside the app. As such the environment within which your commit hooks execute will likely not exactly match that of your normal environment.

    You can take a look at #9351 and see if the workaround in #9351 (comment) is applicable to your situation. One user also had success by changing the husky command from "pre-commit": "lint-staged" to"pre-commit": "npx lint-staged".

    This comment and this comment also have some potential workarounds for this issue.

    Let me know if any of that helps.

  3. ImRodry commented on Sep 9, 2021

    @ImRodry
    Author

    @steveward thanks for the response. I tried all of the suggestions you linked (some didn't apply to my scenario though) and none worked nor did they produce a different kind of error. The error is still the same as the one I attached in the initial message :/

  4. JosefBredereck commented on Nov 12, 2021

    @JosefBredereck

    I get a similar error described in #13307

    But for me, it's bash that fails:

    /usr/bin/env: ‘bash’: No such file or directory
    husky - pre-commit hook exited with code 127 (error)
    

    Additional Info: I have now installed node V14.17.1, and it is working without errors. This issue seems to be connected to the applied version.

  5. nk-o commented on Nov 17, 2021

    @nk-o

    @JosefBredereck same here, after updating node v14 to the latest v16 I see this error from Husky + Lint Staged:
    image

  6. zprjk commented on Dec 10, 2021

    @zprjk

    Similar problem here also. Win10 + Husky v7 + Github Desktop

    Not running through WSL but I have Git Bash installed.

  7. cdaycmc commented on Jan 4, 2022

    @cdaycmc

    I upgraded to Node v16 and husky stopped working with the same error as above. I then downgraded to v14 of Node and it worked again.

    v16.13.1 x64 didn't work (latest LTS)
    v14.18.2 x64 did work

  8. changed the title [-]Desktop tries to run pre-commit scripts on WSL[/-] [+]Desktop fails to run pre-commit hooks on node 16+[/+] on Jan 5, 2022
  9. CameronJThomas commented on Jan 6, 2022

    @CameronJThomas

    I had a parade of issues with Husky 7 and Node 16 on GitHub Desktop, which I resolved by:

    1. Uninstalling WSL (or, if you use it, you can install a distro).
    2. Adding C:\Program Files\Git\bin to my system PATH.
    3. Running git config stash.usebuiltin false in my repository directory.

    At last it is working. The fault seems to lie somewhere between Node 16, and Desktop insisting on using its built in version of Git. 🤷

  10. Airkro commented on Jan 7, 2022

    @Airkro

    Ugly but work:

    npm -> npm.cmd
    npx -> npx.cmd
  11. vtabashniuk commented on Jan 14, 2022

    @vtabashniuk

    Ugly but work:

    npm -> npm.cmd
    npx -> npx.cmd

    helped. Thanks

  12. m-richards commented on Jan 16, 2022

    @m-richards

    Have just run into the same underlying WSL on windows issue trying to use pre-commit (https://github.com/pre-commit/pre-commit), which generates this pre-commit hook after running pre-commit install. INSTALL_PYTHON is generated based upon the environment pre-commit install is run in. But when github desktop runs this on wsl that path is invalid so the script fails.

    #!/usr/bin/env bash
    # File generated by pre-commit: https://pre-commit.com
    # ID: 138fd403232d2ddd5efb44317e38bf03
    
    # start templated
    INSTALL_PYTHON='c:\program files\python39\python.exe'
    ARGS=(hook-impl --config=.pre-commit-config.yaml --hook-type=pre-commit)
    # end templated
    if [ -x "$INSTALL_PYTHON" ]; then
    ...
  13. bschaeublin commented on Jan 27, 2022

    @bschaeublin

    I also get:

    /usr/bin/env: ‘bash’: No such file or directory
    husky - pre-commit hook exited with code 127 (error)
    

    To:

    Ugly but work:

    npm -> npm.cmd
    npx -> npx.cmd

    This is more like a heavy workaround and it gets reverted automatically after updateing I guess.

    @steveward
    It is really weird, that github desktop does not support pre-commit hooks, as it is an essential thing for a git client.
    What could github desktop do, to support it? Use Powershell? Let the user configure an alternative git bash?

  14. added a commit that references this issue on Jan 28, 2022
  15. manzoorwanijk commented on Feb 4, 2022

    @manzoorwanijk

    Any update on this?

  16. 30 remaining items

  17. 1071125093 commented on Apr 12, 2023

    @1071125093

    MARK

  18. badJaguar commented on May 16, 2023

    @badJaguar

    @Puyodead1
    Worked for me!
    React 18+,
    Vite 4.2.0,
    yarn monorepo

  19. mahsarajabpour commented on Jun 11, 2023

    @mahsarajabpour

    This worked for me:
    run this command npx husky-init
    typicode/husky#944 (comment)

  20. Geczy commented on Jan 6, 2024

    @Geczy

    slight optimizations, but the original answer helped

    Use $(...) notation instead of legacy backticks ...

    #!/bin/sh
    . "$(dirname "$0")/_/husky.sh"
    
    case $(uname) in
    *CYGWIN* | *MINGW* | *MSYS*)
      npx.cmd lint-staged # bug on Windows/Github Desktop: add `.cmd` extension fixes it
      ;;
    *)
      npx lint-staged
      ;;
    esac
  21. added a commit that references this issue on Oct 15, 2024
  22. shivam12323 commented on Dec 25, 2024

    @shivam12323

    just check if nvm is installed or not
    nvm --version
    if not than install
    2nd also check it node-v also

  23. smell-of-curry commented on Jun 28, 2025

    @smell-of-curry

    Still an issue, any update?

    FYI, using npm.cmd (appending .cmd to end of your command) will fix it (but might cause issues on UNIX-based machines)

    So the best fix is to add C:\Program Files\Git\bin to System Variables, ensuring you place it after C:\Program Files\Git\cmd. But this will not fix npm commands

    Image

    So I ended up doing this:

    # Universal command helper for cross-platform compatibility
    get_cmd() {
      local cmd="$1"
      case "$(uname)" in
      *CYGWIN* | *MINGW* | *MSYS*)
        echo "${cmd}.cmd"
        ;;
      *)
        echo "$cmd"
        ;;
      esac
    }
    
    $(get_cmd npm) run gen

    Which will allow you to implement new commands very easy.

  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

    windows

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions