Skip to content

Pre-commit hook fails because it can't find lint-staged #11603

Closed

Description

@davehowson

Describe the bug

image
Pre-commit hook fails when I try to commit using GitHub Desktop.

Following is an excerpt of my package.json file

 "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "*.{js,jsx,ts,tsx}": "npm run lint"
  }

This works when trying to commit using the command line and when tried using VSCode's Git integration, but fails on GitHub Desktop.
lint-stage is installed locally and I prefer to keep it that way.

Version & OS

Version 2.6.3
Windows 10 Home

Pinned by niik

Activity

  1. davehowson commented on Feb 16, 2021

    @davehowson
    Author

    I see this issue has occurred to many people but none of the below solutions work

    The fix was rm -f .git/hooks/* and yarn add husky --dev

    changing the husky command from "pre-commit": "lint-staged" to"pre-commit": "npx lint-staged"

  2. steveward commented on Feb 19, 2021

    @steveward
    Contributor

    Thanks for the report @davehowson. Can you try launching GitHub Desktop via the command line by running the github command and then test to see if you still encounter this error? This may be an issue with GitHub Desktop not inheriting your environment.

    It'd also be helpful if you could share the output of $env:path from either CMD or PowerShell.

  3. added
    more-info-needed
    on Feb 19, 2021
  4. davehowson commented on Feb 21, 2021

    @davehowson
    Author

    I tried by running the github command from my projects directory but I still keep getting the same error.
    This is the output of the $env:path

    C:\Windows\system32;
    C:\Windows;
    C:\Windows\System32\Wbem;
    C:\Windows\System32\WindowsPowerShell\v1.0\;
    C:\Windows\System32\OpenSSH\;
    C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;
    C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;
    C:\Program Files\Git\cmd;C:\WINDOWS\system32;
    C:\WINDOWS;C:\WINDOWS\System32\Wbem;
    C:\WINDOWS\System32\WindowsPowerShell\v1.0\;
    C:\WINDOWS\System32\OpenSSH\;
    C:\xampp\php;
    C:\ProgramData\chocolatey\bin;
    C:\Program Files (x86)\Yarn\bin\;
    C:\Program Files\Docker\Docker\resources\bin;
    C:\ProgramData\DockerDesktop\version-bin;
    C:\ProgramData\ComposerSetup\bin;
    C:\nvm;C:\Program Files\nodejs;
    C:\Users\dave\AppData\Local\Programs\Python\Python38\Scripts\;
    C:\Users\dave\AppData\Local\Programs\Python\Python38\;
    C:\Users\dave\AppData\Local\Microsoft\WindowsApps;
    C:\Users\dave\AppData\Local\Programs\Microsoft VS Code\bin;
    C:\Users\dave\AppData\Roaming\nvm;
    C:\Users\dave\AppData\Roaming\Composer\vendor\bin;
    C:\Users\dave\AppData\Local\Yarn\bin;
    C:\Users\dave\AppData\Local\GitHubDesktop\bin;
    C:\Users\dave\AppData\Local\atom\bin;
    C:\Users\user2\AppData\Roaming\nvm\v12.18.0;
    C:\nvm;
    C:\Program Files\nodejs
    
  5. removed
    more-info-needed
    on Feb 21, 2021
  6. ruggi99 commented on Aug 3, 2021

    @ruggi99
    Contributor

    Hi, same issue here for me.
    Using command line, pre-commit hook works but with GitHub Desktop doesn't.
    I installed nvm today and after that pre-commit has stopped working.
    Nvm puts a symlink in C:/Program Files/nodejs that points to the wanted version.
    Could it be that GitHub Desktop cannot follow symlinks?
    EDIT:
    I didn't open a new issue because I saw that @davehowson installed nvm too

  7. ruggi99 commented on Aug 3, 2021

    @ruggi99
    Contributor

    I uninstalled nvm, reinstalled node, restarted Windows and it didn't worked.
    So I reinstalled GitHub Desktop and doesn't work again.
    But in any other terminal I can commit with pre-commit

  8. coderdave commented on Oct 13, 2021

    @coderdave

    What's the status with this? I started github from the command line but it didn't work for me either.

  9. kaisugi commented on May 18, 2022

    @kaisugi

    any updates?

  10. benson00077 commented on Jul 21, 2022

    @benson00077

    Same issue here, with same package.json config + nvm.
    Git command line works well but but with GitHub Desktop doesn't.

  11. rdrinovec commented on Jul 5, 2023

    @rdrinovec

    Same issue here.

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

    @R-Mohammed-Hasan

    github desktop formats files after committing files. I have npm run format to format the files. But after committing, there are some unstaged changes... Can someone please help here

  13. 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
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