How to fix npm ERR! code EPREPAREGIT npm ERR! Error preparing git dependency in npm
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- Verify Git is installed and accessible
- Check Git repository URL and access
- Use HTTPS instead of SSH for Git URLs
- Configure SSH keys if using SSH URLs
git --versionnpm ERR! code EPREPAREGITnpm 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
- 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
- The prepare script in the Git dependency fails because required dependencies or tools are missing
- 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"
First, confirm that Git is installed and available in your system PATH. Open a terminal and run:
git --versionIf Git is not installed, download and install it from https://git-scm.com/download. On macOS with Homebrew:
brew install gitOn Ubuntu/Debian:
sudo apt-get install gitAfter installation, verify again that git --version returns a version number.
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:
{
"dependencies": {
"my-package": "github:user/repo#branch"
}
}Test that the repository is accessible by running:
git ls-remote https://github.com/user/repo.gitReplace 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.
If you're using SSH Git URLs, switch to HTTPS to avoid SSH key configuration issues. Change your package.json from:
{
"dependencies": {
"my-package": "git+ssh://git@github.com/user/repo.git#branch"
}
}To:
{
"dependencies": {
"my-package": "git+https://github.com/user/repo.git#branch"
}
}After updating package.json, delete node_modules and package-lock.json, then reinstall:
rm -rf node_modules package-lock.json
npm installIf you must use SSH URLs, ensure your SSH keys are properly configured. Test SSH connectivity:
ssh -T git@github.comFor 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:
ssh-keyscan -H github.com >> ~/.ssh/known_hostsMake sure your SSH key is added to the ssh-agent:
ssh-add ~/.ssh/id_rsaSometimes npm cache becomes corrupted. Clear it and reinstall:
npm cache clean --force
rm -rf node_modules package-lock.json
npm installIf 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:
npm config set unsafe-perm trueAdvanced 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
- 📚npm Official Documentation
- 📖Docs: npm install(Official Docs)
- 💬SO: npm git preparation errors(Stack Overflow)
- 🐙GitHub: npm repository(GitHub)