The ENOGIT error occurs when npm tries to install packages that depend on Git repositories, but the Git executable is not installed on your system or is not accessible via the system PATH.
The ENOGIT error occurs when npm tries to install packages that depend on Git repositories, but the Git executable is not installed on your system or is not accessible via the system PATH. When npm encounters a package with a Git repository URL as a dependency (e.g., git://github.com/user/project.git), it attempts to use the git command-line tool to clone the repository. If Git is missing or not properly configured in your environment variables, npm fails with "Error while executing: undefined ls-remote". The "undefined" in the error message indicates npm tried to call the git binary but couldn't find it.
Open your terminal/command prompt and run:
git --versionIf you see a version number (e.g., "git version 2.40.0"), Git is installed.
If you see "git: command not found", proceed to Step 2.
Choose the appropriate method for your OS:
Windows:
1. Download the Git installer from https://git-scm.com
2. Run the installer and complete the setup
3. IMPORTANT: Select "Git from Windows Command Prompt" option
macOS:
brew install git
# Or install Xcode Command Line Tools:
xcode-select --installLinux (Debian/Ubuntu):
sudo apt-get update
sudo apt-get install gitLinux (Alpine):
apk add --no-cache gitAfter installing Git, your current terminal session will not have the updated PATH.
On Windows: Close Command Prompt completely and open a new one.
On macOS/Linux: Close your terminal window or restart your shell.
This ensures that your system loads the new PATH environment variable.
If the above steps didn't work on Windows, manually add Git to PATH:
1. Open Environment Variables:
- Press Win + X and select "System"
- Click "Advanced system settings"
- Click "Environment Variables"
- Under "System variables", find and select "Path"
- Click "Edit"
2. Add Git's bin directory (usually):
- C:\Program Files\Git\cmd
3. Click OK on all dialogs and restart your terminal
4. Verify with: git --version
Now that Git is properly installed:
npm installThe installation should proceed without the ENOGIT error.
If you're seeing this error during Docker builds, add Git to your Dockerfile:
For Alpine-based images:
FROM node:alpine
RUN apk add --no-cache git
COPY package*.json ./
RUN npm installFor Debian-based images:
FROM node:18
RUN apt-get update && apt-get install -y git
COPY package*.json ./
RUN npm installThe key is installing git BEFORE running npm install.
Git Dependencies: npm supports installing packages directly from Git repositories using URLs like git+https://github.com/user/project.git#semver:^1.0.0. This is useful for private repositories, unreleased versions, or forks, but requires Git to be available.
PATH Resolution: The PATH environment variable is a list of directories where the OS looks for executable files. When npm tries to run "git", it searches through each directory in PATH until it finds the git executable.
CI/CD Pipelines: GitHub Actions, GitLab CI, and other CI systems typically have Git pre-installed. If builds fail there, check that the CI environment is configured correctly.
Alternative: If you don't want to install Git, consider whether the git dependency in package.json can be replaced with an npm registry package instead.
npm ERR! code E401 npm ERR! 401 Unauthorized - Token has expired
Token has expired - npm authentication failure
npm ERR! code EAI_NODATA npm ERR! errno EAI_NODATA npm ERR! getaddrinfo EAI_NODATA registry.npmjs.org
How to fix "npm ERR! code EAI_NODATA - getaddrinfo EAI_NODATA"
npm ERR! code EMPTYPACKAGE npm ERR! Package contains no files
How to fix 'npm ERR! code EMPTYPACKAGE' - Package contains no files
npm ERR! code EWORKSPACEMISSING npm ERR! Workspace does not exist: packages/missing
How to fix "npm ERR! code EWORKSPACEMISSING - Workspace does not exist" error
npm ERR! code EADDRNOTAVAIL npm ERR! errno EADDRNOTAVAIL npm ERR! Address not available
How to fix "npm ERR! code EADDRNOTAVAIL - Address not available" error