How to fix npm error code ENOENT npm error syscall spawn git npm error path git npm error errno -4058 npm error enoent An unknown git error occurred in npm

npmBEGINNERLOWUpdated May 28, 2026ยท 208 views

npm can't find git on PATH when installing a git dependency. Fix: install Git and reopen your terminal so git is on PATH.

Quick fix

Fixes ENOENT

git --version
  1. Verify if git is installed
  2. Install git
  3. Add git to your PATH (Windows)
  4. Restart your terminal or IDE
npm โ€” error
git --version
npm error code ENOENT npm error syscall spawn git npm error path git npm error errno -4058 npm error enoent An unknown git error occurred

What this error means

The "spawn git ENOENT" error in npm indicates that Node.js attempted to execute the `git` command but could not find the git executable. ENOENT stands for "Error NO ENTry" - a Unix/Linux error code meaning the file or directory does not exist. When you install npm packages that reference git repositories (using `git://` or `git+https://` URLs), or when packages run post-install scripts that invoke git, npm needs access to the git command-line tool. If git isn't installed or isn't in your system's PATH environment variable, this error occurs. This is most common on Windows systems where git was installed but the PATH wasn't updated, or in Docker containers and CI environments where git wasn't included in the base image. On macOS and Linux, git is often pre-installed or automatically added to PATH, making this error less frequent.

Typical symptoms

  • npm install fails with ENOENT error when installing packages from git repositories
  • Post-install scripts fail with spawn git ENOENT
  • Running 'git --version' in terminal returns 'command not found' or is not recognized
  • npm works for regular packages but fails for git-based dependencies
  • Error appears in CI/CD pipelines after changing base Docker image
  • VS Code terminal shows git error while system terminal works fine
  • Error occurs after fresh Windows installation or system reset

Common causes

  1. Git is not installed on the system
  2. Git is installed but not added to the system PATH environment variable
  3. Terminal or IDE was opened before git was installed (PATH not refreshed)
  4. Using a Docker container image that doesn't include git
  5. VS Code or other IDE using a different PATH than system terminal
  6. WSL path translation issues between Windows and Linux environments
  7. CI/CD environment missing git in the build image
  8. Incorrect git.path setting in VS Code or other IDE configuration

How to fix "npm error code ENOENT npm error syscall spawn git npm error path git npm error errno -4058 npm error enoent An unknown git error occurred"

1Verify if git is installed

First, check if git is installed and accessible from your terminal:

bash
git --version

If you see a version number (e.g., git version 2.43.0), git is installed and in your PATH. If you get "command not found" or "'git' is not recognized", git either isn't installed or isn't in your PATH.

On Windows, also try running this in PowerShell:

powershell
Get-Command git

This will show you exactly where git is installed if it's in your PATH.

2Install git

If git isn't installed, install it for your operating system:

Windows:
1. Download from https://git-scm.com/download/win
2. Run the installer
3. Important: Select "Git from the command line and also from 3rd-party software" during installation
4. Complete the installation and restart your terminal

macOS:

bash
# Using Homebrew (recommended)
brew install git

# Or trigger Xcode Command Line Tools installation
xcode-select --install

Ubuntu/Debian Linux:

bash
sudo apt update
sudo apt install git

Fedora/RHEL/CentOS:

bash
sudo dnf install git
# or for older versions:
sudo yum install git

Alpine Linux (Docker):

bash
apk add --no-cache git
3Add git to your PATH (Windows)

If git is installed but not in your PATH, add it manually:

1. Find where git is installed. Common locations:
- C:\Program Files\Git\cmd
- C:\Program Files (x86)\Git\cmd
- C:\Users\YourName\AppData\Local\Programs\Git\cmd

2. Open System Properties:
- Press Win + R, type sysdm.cpl, press Enter
- Go to Advanced tab
- Click Environment Variables

3. Under "System variables" (or "User variables"), find Path and click Edit

4. Click New and add the path to git's cmd folder (e.g., C:\Program Files\Git\cmd)

5. Click OK to close all dialogs

6. Important: Close and reopen your terminal, IDE, or restart your computer for changes to take effect

Quick verification:

powershell
# After restarting terminal
git --version
4Restart your terminal or IDE

Environment variable changes only take effect in new terminal sessions. After installing git or modifying PATH:

Terminal:
- Close all terminal windows and open a new one
- On Windows, you may need to log out and back in, or restart

VS Code:
1. Close VS Code completely (check the system tray on Windows)
2. Reopen VS Code
3. Open a new integrated terminal (Ctrl+ or View > Terminal`)

Other IDEs:
- Close and reopen the IDE
- Some IDEs cache environment variables - check IDE settings if the issue persists

After restarting, verify git is accessible:

bash
git --version
npm install
5Configure git path in VS Code

If git works in your system terminal but not in VS Code's integrated terminal, configure the git path explicitly:

1. Open VS Code Settings (Ctrl+, or Cmd+,)

2. Search for "git path"

3. Set Git: Path to the full path of your git executable:
- Windows: C:\Program Files\Git\bin\git.exe
- macOS/Linux: /usr/bin/git or /usr/local/bin/git

Or edit settings.json directly:

json
{
  "git.path": "C:\\Program Files\\Git\\bin\\git.exe"
}

4. Restart VS Code after changing this setting

6Fix git in Docker containers

If you're running npm in a Docker container, ensure git is installed in your Dockerfile:

Node.js (Debian-based images):

dockerfile
FROM node:20
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .

Node.js Alpine:

dockerfile
FROM node:20-alpine
RUN apk add --no-cache git
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .

Note: Install git before running npm install to ensure it's available for git-based dependencies.

If you only need git during the build phase, consider using multi-stage builds to keep your final image smaller.

7Fix WSL path issues

If you're using Windows Subsystem for Linux (WSL) and experiencing path translation issues:

Option 1: Install git inside WSL:

bash
sudo apt update
sudo apt install git

Option 2: Use Windows git from WSL (if needed):

bash
# Add Windows git to WSL path (in ~/.bashrc or ~/.zshrc)
export PATH="$PATH:/mnt/c/Program Files/Git/cmd"

Option 3: Fix path conversion issues:

bash
# Set this environment variable to prevent path conversion issues
export MSYS_NO_PATHCONV=1

For best results, use the native Linux git inside WSL rather than the Windows version.

Advanced notes

### CI/CD Pipeline Configuration

Ensure git is available in your CI/CD environment:

GitHub Actions:
Git is pre-installed on all GitHub-hosted runners, so this error is rare. If using a custom container, ensure git is installed.

GitLab CI:

yaml
before_script:
  - apt-get update && apt-get install -y git

CircleCI:
Use an image that includes git, or install it:

yaml
steps:
  - run: apt-get update && apt-get install -y git

### Using Git Bash on Windows

If you're on Windows and having persistent PATH issues, try using Git Bash instead of Command Prompt or PowerShell. Git Bash comes with the Git for Windows installer and has git pre-configured in its PATH.

### npm config for git

You can explicitly set the git path for npm:

bash
npm config set git "C:\Program Files\Git\bin\git.exe"

### Debugging PATH Issues

To see your current PATH:

Windows (PowerShell):

powershell
$env:PATH -split ';'

macOS/Linux:

bash
echo $PATH | tr ':' '\n'

Node.js (to see what npm sees):

bash
node -e "console.log(process.env.PATH)"

### Alternative: Use HTTPS URLs

If you can't install git but need to install a package from a git repository, some packages offer alternative installation methods:

bash
# Instead of git URL
npm install git+https://github.com/user/repo.git

# Try tarball URL (if available)
npm install https://github.com/user/repo/archive/main.tar.gz

However, this is a workaround - installing git properly is the recommended solution.

Frequently asked questions

What does "ENOENT" mean?
js attempted to execute the git command but could not find the git executable. ENOENT stands for "Error NO ENTry" - a Unix/Linux error code meaning the file or directory does not exist. When you install npm packages that reference git repositories (using git:// or git+https:// URLs), or when packages run post-install scripts that invoke git, npm needs access to the git command-line tool.
How do I fix "ENOENT"?
npm can't find git on PATH when installing a git dependency. Fix: install Git and reopen your terminal so git is on PATH.
What causes "ENOENT"?
Git is not installed on the system Git is installed but not added to the system PATH environment variable Terminal or IDE was opened before git was installed (PATH not refreshed)
Is the "ENOENT" error serious?
It is a low-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading