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

Error: spawn git ENOENT on Windows 8 #3214

Closed
caedes opened this issue Mar 27, 2017 · 10 comments · Fixed by #8052
Closed

Error: spawn git ENOENT on Windows 8 #3214

caedes opened this issue Mar 27, 2017 · 10 comments · Fixed by #8052

Comments

@caedes
Copy link

caedes commented Mar 27, 2017

Do you want to request a feature or report a bug?

Report a bug.

What is the current behavior?

Bug 1

While running jest --watch on already changed JS files on Zsh, we have an error:

Determining test suites to run...Error: spawn git ENOENT
   at exports._errnoException (util.js:1023:11)
   at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
   at onErrorNT (internal/child_process.js:359:16)
   at _combinedTickCallback (internal/process/next_tick.js:74:11)
   at process._tickCallback (internal/process/next_tick.js:98:9)

Bug 2

While running jest --watch on already changed JS files on Bash, Jest acts like there's no changes at all.

Determining test suites to run...

--no-cache doesn't change anything in both of this processes.

What is the expected behaviour?

I want to see no error and the result of all the tests of the diff shit.

Jest v19.0.2
Node v7.5.0
Windows 8

@caedes caedes changed the title Error: spawn git ENOENT on Windows 8 in a Zsh shell Error: spawn git ENOENT on Windows 8 Mar 27, 2017
@thymikee
Copy link
Collaborator

thymikee commented Mar 31, 2017

Do you have git installed and available through terminal?

@matt-watson90
Copy link

matt-watson90 commented Apr 27, 2017

I am also seeing this behavior using the Jest that comes bundled with the create-react-app (Jest v 18.1.0). I'm running Windows 7 and node v4.4.3

Determining test suites to run...Error: spawn git ENOENT
at exports._errnoException (util.js:870:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:178:32)
at onErrorNT (internal/child_process.js:344:16)
at nextTickCallbackWith2Args (node.js:442:9)
at process._tickCallback (node.js:356:17)

Git is definitely available:

C:\bitbucket\pumping-station-calculator>git --version
git version 2.4.5

If I remove the git repository or set the CI environment variable then everything works as expected.

@Apidcloud
Copy link

Apidcloud commented May 26, 2017

I'm facing the same error on Windows 10. Only doesn't work on Zsh shell.
» npm 3.10.10
» node 6.10.3
» git 2.12.3
» jest 20.0.4

Setting CI flag doesn't seem to fix it.

@meltedice
Copy link

I'm facing the same error on Windows 10, too.

Current workaround to avoid this error is:
Use cmd.exe, instead of MSYS2 bash/zsh.

* git 2.1.2.windows.1     # Installed via MSYS2 pacman
* nodist 0.8.8            # Installed via windows installer
* node v7.10.0            # Installed via nodist
* npm 4.0.5               # Installed via nodist
* create-react-app 1.3.1  # Installed via npm
* jest 20.0.3             # Installed via npm

The Error: spawn git ENOENT error occurs in MSYS2 systems with .git directory.

On cmd.exe, npm test (jest) works well

> create-react-app sample1
> cd sample1
> npm test   # This works
> git init
> npm test   # This works, too

On MSYS2 bash or zsh

% create-react-app sample2
% cd sample2
% npm test   # This works
% git init
% npm test   # This causes 'Error: spawn git ENOENT'

Where this error comes from is jest-changed-files

In git.js, there are childProcess.spawn calls.

const child = childProcess.spawn('git', args, { cwd });

The 3rd argument cwd value is like following:

  • cmd.exe: C:\Users\username\sample1
  • MSYS2 bash: /home/username/sample1
  • MSYS2 zsh: /home/username/sample1

If replace unix style path with windows style path,
jest works on MSYS2 bash or zsh.

Now I just found this, so I don't know who need to care about this.
But I post this on this issue for other developers.

Thanks!

@thymikee
Copy link
Collaborator

@meltedice would you like to work on a proper fix and send a PR if you have some time?

@meltedice
Copy link

@thymikee

I tried some to create PR.
But it seems it's not jest-changed-files issue...
Maybe it's due to my and others' development environment issue.

On windows, it's easy to mix tools that uses different path style.
It causes this problem.
If node.js version manager, git and hg use different path style, jest doesn't work.
(It's hard to solve this mixed path style problem in jest-changed-files)

I think a better way is make sure tools' path style, then use the same path style.
(Better to notice in README.md?)

My cmd.exe on windows environment:

  • where nodist => "C:\Program Files (x86)\Nodist\bin\nodist"
  • where git => "C:\Git\cmd\git.exe"
  • Nodist uses windows style path
  • git uses windows style path
  • yarn test works!

My zsh on msys2 on windows environment:

  • which nodist => "/c/Program Files (x86)/Nodist/bin/nodist"
  • which git => "/usr/bin/git"
  • Nodist uses windows style path
  • git uses unix style path
  • git command result passes unix style path to child-process cwd parameter.
  • yarn test doesn't work.

My fixed zsh on msys2 on windows environment:

  • Nodist uses windows style path
  • force git to use windows style path for yarn and npm
  • which nodist => "/c/Program Files (x86)/Nodist/bin/nodist"
  • PATH=/c/Git/cmd/:$PATH git => /c/Git/cmd/git
  • PATH=/c/Git/cmd/:$PATH yarn test works!
  • alias yarn="PATH=/c/Git/cmd/:\$PATH yarn"
  • alias npm="PATH=/c/Git/cmd/:\$PATH npm"
  • yarn test and npm test work!

So my solution is add following into .bashrc or .zshrc for msys2:

alias yarn="PATH=/c/Git/cmd/:\$PATH yarn"
alias npm="PATH=/c/Git/cmd/:\$PATH npm"

If I can install another node.js version manager into msys2 system,
I don't need to do above trick.

node.js git/hg jest
Windows system Windows system works
Windows system msys2 system doesn't work
msys2 system Windows system maybe doesn't work
msys2 system msys2 system maybe works

If there are unclear parts or something what I can do, let me know.

Thanks,

@cpojer
Copy link
Member

cpojer commented Aug 24, 2017

We currently don't have bandwidth to support these use cases, nor do we have Windows machines. If you'd like this to be fixed, please send us a PR. From our side, this is not really actionable, so I'm closing this issue.

@cpojer cpojer closed this as completed Aug 24, 2017
@GabeDuarteM
Copy link

I was facing the same issue when using Cygwin.

I was able to solve it renaming "C:\cygwin64\bin\git.exe" to "C:\cygwin64\bin\git.exe.bak". That way, jest will use the same git that cmd uses, and everything works fine (at least until now)

@bwiercinski
Copy link
Contributor

bwiercinski commented Mar 5, 2019

@GabrielDuarteM at this point of time this answer is incorrect :(,
but i found out that root of git repo is injected incorrectly
from: getRoot
https://github.com/facebook/jest/blob/481334b6/packages/jest-changed-files/src/git.ts

git rev-parse --show-toplevel is returning /cygdrive/c/Users/... instead of C:\Users\...

to fix this we should parse this with cygpath -w, but this would fix this bug only for cygwin, what with other unix emulators on windows like msys2 or mingw

we need a way to obtain root of git project as a WINDOWS path instead of cygwin path..., but without cygpath -w any ideas? im able to do PR to fix this but sadly only for cygwin which is bad.

damn windows, why i'm still with you

edit:
we can replace --show-toplevel with --show-cdup
and use path.join(cwd, result.stdout)

DuosBros pushed a commit to DuosBros/Project2 that referenced this issue Jul 19, 2019
Add CI=1 env var to work around an issue with jest on windows.
See jestjs/jest#3214 (comment)
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants