Skip to content

Windows 10 - cygpath: command not found #10999

Closed

Description

@owenashurst

Describe the bug

When attempting to commit or push a branch I am given an error about cygpath not being found.

Git For Windows is installed on my system and running the commands manually in a command prompt works fine. GitHub desktop preferences has the shell set to Command Prompt also which I would have thought would solve the issue, but it does not. Changing it to Git Bash also does not appear to have any effect.

Version & OS

Version 2.5.7
Windows 10 Pro - 10.0.18363 Build 18363

Steps to reproduce the behavior

  1. Make a commit on a project that uses pre-commit hooks using husky.
  2. Observe the error message

OR

  1. Create a branch on a project that uses pre-commit hooks using husky
  2. Push the branch
  3. Observe the error message

Expected behavior

Should commit and run the pre-commit hooks.

Actual behavior

Throws the following error;

/c/dev/work/SomeProject/node_modules/.bin/npm: line 5: cygpath: command not found
internal/modules/cjs/loader.js:985
  throw err;
  ^

Error: Cannot find module 'C:\npm\bin\npm-cli.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:982:15)
    at Function.Module._load (internal/modules/cjs/loader.js:864:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
error: failed to push some refs to 'https://github.com/SomeUser/SomeProject.git'

Logs

2020-11-09T11:33:23.145Z - info: [ui] Executing createCommit: git commit -F - (took 1.401s)
2020-11-09T11:33:23.149Z - error: [ui] `git commit -F -` exited with an unexpected code: 1.
stderr:
husky > pre-commit (node v12.16.1)
/c/dev/work/SomeProject/node_modules/.bin/lint-staged: line 5: cygpath: command not found
internal/modules/cjs/loader.js:985
  throw err;
  ^

Error: Cannot find module 'C:\lint-staged\bin\lint-staged.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:982:15)
    at Function.Module._load (internal/modules/cjs/loader.js:864:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Activity

  1. steveward commented on Nov 9, 2020

    @steveward
    Contributor

    Thanks for the report @owenashurst. This looks similar to #9278.

    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". I hope that helps!

  2. owenashurst commented on Nov 12, 2020

    @owenashurst
    Author

    @steveward Unfortunately neither of those solutions worked in my case. That seems like a different issue possibly?

    Could this bug be reopened please since the issue is still on-going?

  3. steveward commented on Nov 13, 2020

    @steveward
    Contributor

    @owenashurst unfortunately this is a specific issue with the configuration of your pre-commit hook script so there isn't much we can do on our end. Did you try running the git config stash.usebuiltin false command to see if that worked?

  4. owenashurst commented on Nov 14, 2020

    @owenashurst
    Author
  5. vicortez commented on Dec 21, 2020

    @vicortez

    (windows 10) I was having the same problem as @owenashurst. Some commands on husky worked, but the vast majority threw errors like the one described here and on #9278. All of them seemed to be because Github Desktop's shell was looking for the commands on the C:\ folder, and with a .js extension, ex if i ran the npm command: Error: Cannot find module 'C:\npm\bin\npm-cli.js', or the commitlint command: Error: Cannot find module 'C:\@commitlint\cli\cli.js'.

    I was using husky v4 and this is my husky.config.js file:
    module.exports = { hooks: { 'commit-msg': 'commitlint -E HUSKY_GIT_PARAMS', }, }

    Changing the hook command from 'commit-msg': 'commitlint -E HUSKY_GIT_PARAMS', to 'commit-msg': 'commitlint.cmd -E HUSKY_GIT_PARAMS', fixed the problem for me, but that would probably affect others working on linux, so its not viable in my case.

    Deleting my husky files in .git/hooks and downgrading to v3 (npm uninstall husky && npm install --save-dev husky@3) solved the issue for me. Now it sucessfully goes after the correct commitlint cli file in my project's node_modules.

  6. pmachapman commented on Jun 22, 2021

    @pmachapman

    I fixed this by installing the latest Git for Windows, then copying C:\Program Files\Git\usr\bin\cygpath.exe to
    %HOMEPATH%\AppData\Local\GitHubDesktop\app-2.9.0\resources\app\git\usr\bin.

    Not elegant, but it showed only one command was missing.

  7. longergrass commented on Jul 13, 2021

    @longergrass

    @pmachapman Thanks, that worked perfectly!

  8. realdeepak commented on Jul 14, 2021

    @realdeepak

    @pmachapman it worked. Thanks

  9. radziksh commented on Aug 17, 2021

    @radziksh

    I fixed this error by starting GitHub Desktop as administrator. Not sure why, but it worked for me.

  10. 04487 commented on Aug 17, 2021

    @04487
  11. 04487 commented on Aug 17, 2021

    @04487
  12. owenashurst commented on Aug 17, 2021

    @owenashurst
    Author

    I fixed this by installing the latest Git for Windows, then copying C:\Program Files\Git\usr\bin\cygpath.exe to
    %HOMEPATH%\AppData\Local\GitHubDesktop\app-2.9.0\resources\app\git\usr\bin.

    Not elegant, but it showed only one command was missing.

    @pmachapman Thanks! Just tried it then and solved it. Looks like it's missing in the version GitHub desktop ships with.

    @steveward Any comments on this?

  13. rnwonder commented on Apr 5, 2022

    @rnwonder

    @pmachapman Thanks a lot

  14. axelvalles commented on Dec 8, 2022

    @axelvalles

    I fixed this by installing the latest Git for Windows, then copying C:\Program Files\Git\usr\bin\cygpath.exe to %HOMEPATH%\AppData\Local\GitHubDesktop\app-2.9.0\resources\app\git\usr\bin.

    Not elegant, but it showed only one command was missing.

    @pmachapman it worked. Thanks

  15. 1071125093 commented on Apr 12, 2023

    @1071125093

    I fixed this by installing the latest Git for Windows, then copying C:\Program Files\Git\usr\bin\cygpath.exe to %HOMEPATH%\AppData\Local\GitHubDesktop\app-2.9.0\resources\app\git\usr\bin.

    Not elegant, but it showed only one command was missing.

    @pmachapman not elegant,but the only way and worked , thanks

  16. Mobbbb commented on Jul 22, 2024

    @Mobbbb

    I fixed this by installing the latest Git for Windows, then copying C:\Program Files\Git\usr\bin\cygpath.exe to %HOMEPATH%\AppData\Local\GitHubDesktop\app-2.9.0\resources\app\git\usr\bin.

    Not elegant, but it showed only one command was missing.

    @pmachapman Nice! It worked. By the way. GitHubDesktop is indeed inferior to Sourcetree.

  17. AndreasOngCWANZ commented on Aug 11, 2024

    @AndreasOngCWANZ

    Thanks this is working

    • Install new GIT
    • Install new GIT HUB Desktop
    • Copy the C:\Program Files\Git\usr\bin\cygpath.exe to %HOMEPATH%\AppData\Local\GitHubDesktop\app-3.4.3\resources\app\git\usr\bin

    Note the App Version folder will be available once you install the new GITHUB desktop

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