This error occurs when npm cannot find the specified Git branch, tag, or commit for a Git-based dependency. The reference you're trying to install doesn't exist in the repository, or npm can't access it.
The EPREPAREGIT error happens during the preparation phase of installing a Git-based dependency. When you specify a Git URL in package.json with a reference (like `git+https://github.com/user/repo.git#branch-name`), npm attempts to clone the repository and checkout the exact reference you specified. If that reference (branch, tag, or commit SHA) doesn't exist or isn't accessible, npm fails with EPREPAREGIT. The error typically means one of three things: (1) the reference doesn't exist in the repository, (2) npm can't authenticate to access a private repository, or (3) network connectivity is preventing npm from reaching the Git server.
Before anything else, confirm that the branch, tag, or commit you're trying to use actually exists. Use git ls-remote to check:
git ls-remote https://github.com/user/repo.gitThis will list all branches, tags, and refs available. Look for the exact reference you specified in package.json. Common mistakes:
- Using 'master' when the default branch is 'main'
- Missing the 'v' prefix on tags (e.g., using '1.0.0' instead of 'v1.0.0')
- Referencing a branch that was deleted or renamed
Once you've confirmed the correct reference exists, update your package.json with the exact name:
{
"dependencies": {
"my-package": "git+https://github.com/user/repo.git#main",
"private-package": "git+ssh://[email protected]:user/private-repo.git#v2.1.0"
}
}Note the syntax:
- git+https:// for HTTPS URLs
- git+ssh:// for SSH URLs
- #branch-name, #tag-name, or #commit-sha for the reference
npm caches Git repositories, and stale cache can cause issues. Clear it forcefully:
npm cache clean --forceThen delete your local dependency files:
rm -rf node_modules package-lock.jsonThis ensures npm will fetch fresh data from the remote repository instead of using cached information.
Now install fresh:
npm installIf you're working with private repositories and still see EPREPAREGIT, you likely have an authentication issue. Test your Git access:
ssh -T [email protected]For HTTPS with GitHub, you may need to use a Personal Access Token (PAT) instead of your password.
Sometimes one protocol works better than the other. If you were using SSH and it failed, try HTTPS:
{
"dependencies": {
"my-package": "git+https://github.com/user/repo.git#branch"
}
}You can also configure git globally to prefer one protocol:
git config --global url."https://github.com/".insteadOf [email protected]:For organizations using GitHub: ensure your personal access token has the correct scopes (repo, read:packages). For self-hosted Git servers behind firewalls, you may need to configure an HTTP proxy. If you need semantic versioning with Git dependencies, use the special semver: prefix in the reference: git+https://github.com/user/repo.git#semver:^1.0.0 - npm will search tags matching that version range.
npm ERR! code ENOAUDIT npm ERR! Audit endpoint not supported
How to fix "npm ERR! code ENOAUDIT - Audit endpoint not supported"
npm ERR! code EBADDEVENGINES npm ERR! devEngines.runtime incompatible with current node version
How to fix "npm ERR! code EBADDEVENGINES - devEngines.runtime incompatible with current node version"
npm ERR! code ETOOMANYARGS npm ERR! Too many arguments
How to fix "npm ERR! code ETOOMANYARGS - Too many arguments"
npm ERR! code EINVALIDTAGNAME npm ERR! Invalid tag name: tag names cannot contain spaces
How to fix "npm ERR! code EINVALIDTAGNAME - tag names cannot contain spaces"
npm ERR! code E400 npm ERR! 400 Bad Request
How to fix "npm ERR! code E400 - 400 Bad Request" error