How to fix npm ERR! code EPREPAREGIT npm ERR! Error preparing git dependency in npm

npmINTERMEDIATEHIGHUpdated Dec 5, 2025· 129 views

EPREPAREGIT occurs when npm fails to prepare a package installed directly from a Git repository. This typically happens due to missing Git, invalid repository URLs, failed prepare scripts, or SSH/authentication issues.

Quick fix

Fixes npm ERR! code EPREPAREGIT npm ERR! Error preparing git dependency

git --version
  1. Verify Git is installed and accessible
  2. Check Git repository URL and access
  3. Use HTTPS instead of SSH for Git URLs
  4. Configure SSH keys if using SSH URLs
npm — error
git --version
npm ERR! code EPREPAREGIT
npm ERR! Error preparing git dependency

What this error means

The EPREPAREGIT error indicates that npm encountered a failure while preparing a Git dependency for installation. When you specify a dependency using a Git URL in package.json (e.g., `github:user/repo#branch`), npm clones the repository and runs any `prepare` or `postinstall` scripts defined in that package. If any step fails—whether it's cloning the repo, checking out a specific branch/tag, or executing the prepare script—npm throws this error. This is different from regular npm package installation because Git dependencies require additional setup steps: fetching from a remote Git server, verifying access credentials, and running build/preparation commands. Any failure in these steps prevents the dependency from being properly installed.

Typical symptoms

  • npm install fails with 'npm ERR! code EPREPAREGIT' in the error output
  • Installation works on some machines but fails on others (e.g., different developers, Docker containers, CI/CD)
  • Error message includes 'git ls-remote' or 'fatal: Could not read from remote repository'
  • npm install succeeds after clearing cache and node_modules, then fails again on subsequent installs
  • The error occurs immediately after npm tries to fetch a specific Git URL dependency

Common causes

  1. Git is not installed or not available in the system PATH, preventing npm from cloning the repository
  2. SSH keys are not configured or the host key is not verified when using SSH Git URLs
  3. The Git reference (branch, tag, or commit) specified in package.json no longer exists in the repository
  4. The prepare script in the Git dependency fails because required dependencies or tools are missing
  5. The Git repository URL is incorrect, inaccessible, or the repository has been deleted or made private

How to fix "npm ERR! code EPREPAREGIT npm ERR! Error preparing git dependency"

1Verify Git is installed and accessible

First, confirm that Git is installed and available in your system PATH. Open a terminal and run:

bash
git --version

If Git is not installed, download and install it from https://git-scm.com/download. On macOS with Homebrew:

bash
brew install git

On Ubuntu/Debian:

bash
sudo apt-get install git

After installation, verify again that git --version returns a version number.

2Check Git repository URL and access

Verify that the Git URL in your package.json is correct and you have access to it. Open package.json and find your Git dependency:

json
{
  "dependencies": {
    "my-package": "github:user/repo#branch"
  }
}

Test that the repository is accessible by running:

bash
git ls-remote https://github.com/user/repo.git

Replace with your actual repository URL. If the command fails, either the URL is incorrect, the repository doesn't exist, or you don't have access permissions.

3Use HTTPS instead of SSH for Git URLs

If you're using SSH Git URLs, switch to HTTPS to avoid SSH key configuration issues. Change your package.json from:

json
{
  "dependencies": {
    "my-package": "git+ssh://git@github.com/user/repo.git#branch"
  }
}

To:

json
{
  "dependencies": {
    "my-package": "git+https://github.com/user/repo.git#branch"
  }
}

After updating package.json, delete node_modules and package-lock.json, then reinstall:

bash
rm -rf node_modules package-lock.json
npm install
4Configure SSH keys if using SSH URLs

If you must use SSH URLs, ensure your SSH keys are properly configured. Test SSH connectivity:

bash
ssh -T git@github.com

For GitHub, this should return something like: "Hi username! You've successfully authenticated..."

If it fails with "Host key verification failed", add GitHub to your known_hosts:

bash
ssh-keyscan -H github.com >> ~/.ssh/known_hosts

Make sure your SSH key is added to the ssh-agent:

bash
ssh-add ~/.ssh/id_rsa
5Clear cache and reinstall dependencies

Sometimes npm cache becomes corrupted. Clear it and reinstall:

bash
npm cache clean --force
rm -rf node_modules package-lock.json
npm install

If you're in a Docker container, ensure you're running npm install as a non-root user or with the correct permissions. If running as root causes issues, use:

bash
npm config set unsafe-perm true

Advanced notes

When npm installs a Git dependency, it clones the repository to a temporary location, runs the prepare and prepack scripts (if defined), and then copies the prepared package into node_modules. The prepare script has access only to the package's own dependencies, not to devDependencies—this is a common source of failures. In Docker containers, use the full Node image rather than Alpine-based images, as Alpine may lack build tools.

Frequently asked questions

What does "npm ERR! code EPREPAREGIT npm ERR! Error preparing git dependency" mean?
The EPREPAREGIT error indicates that npm encountered a failure while preparing a Git dependency for installation. , github:user/repo#branch), npm clones the repository and runs any prepare or postinstall scripts defined in that package. If any step fails—whether it's cloning the repo, checking out a specific branch/tag, or executing the prepare script—npm throws this error.
How do I fix "npm ERR! code EPREPAREGIT npm ERR! Error preparing git dependency"?
EPREPAREGIT occurs when npm fails to prepare a package installed directly from a Git repository. This typically happens due to missing Git, invalid repository URLs, failed prepare scripts, or SSH/authentication issues.
What causes "npm ERR! code EPREPAREGIT npm ERR! Error preparing git dependency"?
Git is not installed or not available in the system PATH, preventing npm from cloning the repository SSH keys are not configured or the host key is not verified when using SSH Git URLs The Git reference (branch, tag, or commit) specified in package.json no longer exists in the repository
Is the "npm ERR! code EPREPAREGIT npm ERR! Error preparing git dependency" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading