Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug?]: Yarn crashes in pre-commit hook when comitting via Visual Studio GUI #4095

Closed
1 task done
srmagura opened this issue Feb 9, 2022 · 3 comments
Closed
1 task done
Labels
bug Something isn't working

Comments

@srmagura
Copy link

srmagura commented Feb 9, 2022

Self-service

  • I'd be willing to implement a fix

Describe the bug

We have a pre-commit hook that uses Yarn to run a script. It works fine for everyone except my coworker who wants to commit from the Visual Studio GUI.

It appears that the Yarn executable is looking for yarn.js in the wrong location. I took a look at the yarn shell script (AppData\Roaming\npm\node_modules\yarn\bin\yarn), and it looks like there is some semi-complex logic for determining the correct directory. I am wondering if this logic is not working correctly in this case.

To reproduce

https://github.com/srmagura/yarn-visual-studio-repro

  1. Open the folder in Visual Studio 2022.
  2. Edit any file.
  3. Try to commit via the Visual Studio GUI.

Expected behavior: The commit goes through.

Actual behavior: There is an error.

/c/Users/sam.magura/AppData/Roaming/npm/yarn: line 5: cygpath: command not found
node:internal/modules/cjs/loader:936
  throw err;
  ^

Error: Cannot find module 'C:\program files\microsoft visual studio\2022\enterprise\common7\ide\commonextensions\microsoft\teamfoundation\team explorer\Git\node_modules\yarn\bin\yarn.js'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Function.executeUserEntryPoint  as runMain
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
husky - pre-commit hook exited with code 1 (error)

Environment

System:
    OS: Windows 10 10.0.22000
    CPU: (32) x64 AMD Ryzen 9 5950X 16-Core Processor
  Binaries:
    Node: 16.13.1 - C:\Users\SAM~1.MAG\AppData\Local\Temp\xfs-3d85d2a3\node.CMD
    Yarn: 3.1.1 - C:\Users\SAM~1.MAG\AppData\Local\Temp\xfs-3d85d2a3\yarn.CMD
    npm: 8.3.0 - C:\Program Files\nodejs\npm.CMD

Additional context

Let me know if this is not a Yarn issue but rather a Visual Studio issue.

@srmagura srmagura added the bug Something isn't working label Feb 9, 2022
@arcanis
Copy link
Member

arcanis commented Feb 9, 2022

Doesn't seem related to Yarn, as it references cygpath being missing.

@srmagura
Copy link
Author

srmagura commented Feb 9, 2022

Thanks! Fixed adding the following to my pre-commit:

# Make cygpath accessible. This is necessary for Yarn to work when committing
# via Visual Studio.
PATH=$PATH:"/c/Program Files/Git/usr/bin"

Related issue: desktop/desktop#10326

@srmagura srmagura closed this as completed Feb 9, 2022
@merceyz
Copy link
Member

merceyz commented Feb 9, 2022

I've seen this before and it was caused by the files created by npm when it installs yarn, the files created by Corepack haven't shown the same issue so I suggest trying that https://yarnpkg.com/getting-started/install .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants