Yarn: Error: Couldn't find the binary git

Created on 30 Nov 2016  ·  43Comments  ·  Source: yarnpkg/yarn

I am using:

  • yarn v0.17.9
  • macOS Sierra 10.12.1
  • Node v6.9.1

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

Bug

What is the current behavior?

Trying to install packages using yarn. Outputs a strange error message:

[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
error Couldn't find the binary git

If the current behavior is a bug, please provide the steps to reproduce.

yarn --pure-lockfile

Outputs the above error message.

Git is installed:

Admins-Mac-mini:BWA-BETA203-FAST admin$ whereis git
/usr/bin/git

What is the expected behavior?

Yarn should install the packages without emitting an error about git. If I run this command using an older version of yarn, v0.16.1, everything is fine.

cat-bug

Most helpful comment

@alansouzati I believe you need to install git previously, for example:

pipeline:
  test:
    image: node:7-alpine
    commands:
      - apk add --no-cache git
      - yarn

All 43 comments

What's the result of which git?

Admins-Mac-mini:~ admin$ which git
/usr/local/bin/git

That's a different path to whereis git.

+1 - same problem macOS 10.12.1

yarn --version
0.17.10

node -v
v6.9.1

which git                           
/usr/local/bin/git

whereis git
/usr/bin/git

and on windows 7 and 10 with git-scm

I have the same problem under ubuntu 16.04, dans yarn 18.1.

The reported error is bad:
The node spawn call return a "ENOENT" error (https://github.com/yarnpkg/yarn/blob/master/src/util/child.js#L41)
This is not caused by the git binary not found, but by the cwd given in opts witch is not found.

This is because of the supportsArchive boolean:

  • either archive is not supported, and everything is cloned locally.
  • or archive is used and nothing is cloned

However, supportArchive can change while nothing was cloned (https://github.com/yarnpkg/yarn/blob/master/src/util/git.js#L338).

Same thing happened to me after a yarn cache clean (trying to get a git branch dependency to update).

Removing the node_modules folder and running yarn again seemed to work around the issue.

this happens here too after yarn cache clean both on linux and Mac

I am experiencing this issue too. I started seeing it after running yarn cache clean && yarn clean.

I use a Mac

Unfortunately even deleting node_modules/ doesn't fix the problem

This seems to happen to me when using a "git+ssh" dependency where the commit hash is not at the HEAD of the branch. For example, my lockfile contains something like:

"foo-bar-baz@git+ssh://[email protected]:7999/asdf/foo-bar-baz.git":
  version "2.2.2"
  resolved "[email protected]:7999/asdf/foo-bar-baz.git#a5e6897042a496d70dbc57b1de8f8df5e8c0369c"
  dependencies:
...

At first, a5e6897042a496d70dbc57b1de8f8df5e8c0369c was the HEAD of the repo and yarn install worked fine. But when I committed some new revs to foo-bar-baz.git without updating the lockfile of the package making use of foo-bar-baz (because I didn't need to yet), then yarn install started failing with the 'Couldn't find the binary git' message.

a5e6897042a496d70dbc57b1de8f8df5e8c0369c still exists in the repo and npm can install it just fine.

If I manually change the commit hash in the lockfile to whatever the HEAD commit hash is in foo-bar-baz.git, yarn install starts working again.

Starting with an empty cache definitely triggers this behavior. Starting with previously cached packages may or may not trigger it. Not sure why.

Happens with yarn 0.18.1 and 0.19.1. Node 6.9.1

Had the same problem as @sirbarrence . After removing the lockfile it worked again

Thanks @sirbarrence - that was spot on. If the commit referred to in yarn.lock isn't the head of the referenced branch then we get the error. The workaround is to manually edit the yarn.lock file and delete the section for the dependency in question. Running yarn again after this works and picks up the new commit.

Thanks @vitch that can work for local development. For automated builds where manual intervention is undesirable or builds where you can't use the HEAD of the dependency yet for compatibility reasons, I'm having to consider reverting to npm until this is resolved.

Seeing this as well - exactly the same setup as @sirbarrence

Looks like it might be fixed in 0.20 - https://github.com/yarnpkg/yarn/releases/tag/v0.20.0

image

I confirm that 0.20 fixes it

Happens with Windows8 yarn 0.20.3 Node 6.9.5.

E:codesjsreactrelax-master>yarn --version
0.20.3

E:codesjsreactrelax-master>node -v
v6.9.5

E:codesjsreactrelax-master>yarn install
yarn install v0.20.3
[1/4] Resolving packages...
[2/4] Fetching packages...
error Couldn't find the binary git
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

I was having this same issue on yarn 0.21.3. Switching from the abbreviated SHA commit hash to the full SHA commit hash solved the problem for me.

I cannot experience this problem locally, but my CI (Drone CI) keeps hitting this problem. We have the same yarn version.

@alansouzati I believe you need to install git previously, for example:

pipeline:
  test:
    image: node:7-alpine
    commands:
      - apk add --no-cache git
      - yarn

thanks @ricardogama, my CI is passing now.

I think this issue should be marked as resolved now.
The fix has been merged and is in the stable releases for a long time.

I'm seeing this issue on Ubuntu 16.04, because nodejs is still at version 4... If I upgrade to 6.. it seems to fix it.

Closed since this seems to be resolved in recent versions.

Yep - definitely resolved for me.

I just hit this on the current node:9-alpine image, and my yarn.lock doesn't have any git+ssh deps, but does have an yeoman-generator "https://github.com/ev1stensberg/generator.git#Feature-getArgument" via webpack-cli

Using Docker executor with image node:9-alpine ...
Using docker image sha256:12be62a1f685f3f79041ec45abd2d7b8cc7d6f12a7f65c9071b6a4356cd1d352 for predefined container...
Pulling docker image node:9-alpine ...
Using docker image node:9-alpine ID=sha256:e90a5bfd29f6e9ea9f7813c0bed6350d7c5a07efc689a4b553ac6ae10abf1f90 for build container...
Running on runner-b2c67c2a-project-59-concurrent-0 via b3c8740cb0fc...
Cloning repository...
Cloning into '/builds/interact/example-keyword-parser'...
Checking out 83d17370 as master...
Skipping Git submodules setup
Checking cache for default...
FATAL: file does not exist                         
Failed to extract cache
$ yarn
yarn install v1.3.2
[1/4] Resolving packages...
[2/4] Fetching packages...
error Couldn't find the binary git
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
ERROR: Job failed: exit code 1

Do you want a new issue?

1.5.1 and still the same issue

Hi - I am still facing this issue.
here is the output log:
yarn-error.log

Requires git to build your computer. https://git-scm.com/

I am running git from Ubuntu/WSL via PowerShell on Windows 10 using this git.bat in my path:

@echo off
setlocal enabledelayedexpansion
set command=%*
If %PROCESSOR_ARCHITECTURE% == x86 (
    echo | C:\Windows\sysnative\bash.exe -c 'git %command%'
) Else (
    echo | bash.exe -c 'git %command%'
)

Git works OK from PowerShell but not from Yarn-within-powershell:

PS C:\temp> git --version
git version 2.7.4
PS C:\temp> yarn --version
1.7.0
PS C:\temp> node --version
v8.11.3
PS C:\temp> yarn install
yarn install v1.7.0
[1/4] Resolving packages...
[2/4] Fetching packages...
error Couldn't find the binary git
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

For reference: when I had this error message, adding ssh:// resolved it for me. npm is able to deal with [email protected]:etc, but yarn required git+ssh://[email protected]:etc. The error message was not helpful to understand what was wrong, I had to see here that basically any error while fetching a git dependency causes this message to even consider that my dependency spec may need to be changed.

yarn -v shows 1.10.1

Delete yarn.lock file
Try to run yarn install

@ricardogama thanks, i have same problem in node:11.5-alpine, after install git by apk it solved

This issue is still occurring for me when run on my Jenkins server (although fine locally).

Node: 12.6.0
Yarn: 1.16.0

I can find the full repository that I am trying to install in the Yarn/Cache folder, so the failure must be occuring after yarn performs the git clone (so yarn also clearly has access to the git binary at some point to be able to clone)

I tried the various git+ssh://... suggestions above with no success. Any other ideas?

Hey! I found that problem occurs in case when you add a dependency, this way

    "@assets/sprintf": "https://github.com/alexei/sprintf.js#^1.1.1",

after I changed this line to

    "@assets/sprintf": "alexei/sprintf.js#^1.1.1",

the problem is gone

For reference: when I had this error message, adding ssh:// resolved it for me. npm is able to deal with [email protected]:etc, but yarn required git+ssh://[email protected]:etc. The error message was not helpful to understand what was wrong, I had to see here that basically any error while fetching a git dependency causes this message to even consider that my dependency spec may need to be changed.

yarn -v shows 1.10.1

Thanks, this is working for me now

I solved this error by installing git on my computer

Sometimes it could be just that path to git is not added to the PATH environmental variable.
For Windows add these two (adjust if git is installed on different location):
C:Program FilesGitbin
C:Program FilesGitcmd

Install git at https://git-scm.com/
Run yarn cache clean and delete node_modules folder
Restart your terminal (To make sure that it recognizes that git is now installed)

Hey! I found that problem occurs in case when you add a dependency, this way

    "@assets/sprintf": "https://github.com/alexei/sprintf.js#^1.1.1",

after I changed this line to

    "@assets/sprintf": "alexei/sprintf.js#^1.1.1",

the problem is gone

This caused my build to just hang forever

simply install git on your system

  1. Use the following link to download Git
    https://git-scm.com/download
  2. Install it in your machine.
  3. Restart your machine.
  4. Try running same command again and it will no more throw error.
    Thanks @swushi It worked.

Have you correctly set your PATH to point at your Git installation?

You need to add the following paths to PATH:

C:Program FilesGitbin
C:Program FilesGitcmd
And check that these paths are correct – you may have Git installed on a different drive, or under Program Files (x86). Correct the paths if necessary.

@alansouzati I believe you need to install git previously, for example:

pipeline:
  test:
    image: node:7-alpine
    commands:
      - apk add --no-cache git
      - yarn

Can u please elaborate how you had done this ??

Have you correctly set your PATH to point at your Git installation?

You need to add the following paths to PATH:

C:Program FilesGitbin
C:Program FilesGitcmd
And check that these paths are correct – you may have Git installed on a different drive, or under Program Files (x86). Correct the paths if necessary.

Had to restart windows my PC then it worked after doing this (y)

Was this page helpful?
0 / 5 - 0 ratings