I am working on a project that has Husky dependency. When I try to commit changes or switch branch on GitHub Desktop, I get this error:
2022-11-16T12:18:08.885Z - error: [ui] `git commit -F -` exited with an unexpected code: 1.
stderr:
/c/Users/user/AppData/Roaming/npm/yarn: line 5: cygpath: command not found
node:internal/modules/cjs/loader:988
throw err;
^
Error: Cannot find module 'C:\Users\user\AppData\Local\GitHubDesktop\app-3.1.2\resources\app\git\node_modules\yarn\bin\yarn.js'
at Module._resolveFilename (node:internal/modules/cjs/loader:985:15)
at Module._load (node:internal/modules/cjs/loader:833:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Node.js v18.10.0
husky - pre-commit hook exited with code 1 (error)
OS: Windows 10 Pro
GitHub Desktop: Version 3.1.2
Git: Version 2.38.0.windows.1
If i use git from Powershell, everything works fine.
So the problem is, there is no C:\Users\user\AppData\Local\GitHubDesktop\app-3.1.2\resources\app\git\node_modules\yarn\bin\yarn.js
My first assumption is that there is no npm initialized in the git
folder. Let's check:
1- Open Powershell
2- Type cd C:\Users\user\AppData\Local\GitHubDesktop\app-3.1.2\resources\app\git
to set the directory
3- Type explorer .
to view the folder in File Explorer
So we see no node_modules
, package.json
or package-lock.json
. This means that npm is not initialized in this current directory.
To add the missing ...\git\node_modules\yarn\bin\yarn.js
:
1- Run npm init
to initialize npm in the directory.
2- Run npm i yarn
to add yarn dependency to the current directory.
This way, we have added the missing ...\git\node_modules\yarn\bin\yarn.js
file.
Now everything works fine!
Accepted answer works, but you need to repeat it after every update of GitHub as the path will change (as per version name).
The key here is cygpath: command not found
. cygpath is shipped with Git and is present in C:\Program Files\Git\usr\bin. Add that to PATH and the problem will be fixed permanently.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With