How to fix npm ERR! code 128 npm ERR! git clone --mirror git://github.com/user/repo.git failed with code 128 in npm
Exit code 128 is a fatal Git error that occurs when npm fails to clone a repository during dependency installation. This typically happens when Git encounters permission denial, network failure, or authentication issues.
Quick fix
Fixes npm ERR! code 128 npm ERR! git clone --mirror git://github.com/user/repo.git failed with code 128
npm cache clean --force- Clear npm cache and verify Git is working
- Check and fix SSH key configuration
- Test Git access to the repository
- Switch from SSH to HTTPS if SSH is blocked
npm cache clean --forcenpm ERR! code 128npm ERR! git clone --mirror git://github.com/user/repo.git failed with code 128
What this error means
Exit code 128 is a fatal Git error that occurs when npm fails to clone a repository during dependency installation. This typically happens when npm runs "git clone --mirror" to cache a Git-based dependency. The error indicates that Git encountered an unrecoverable problem such as: - Permission denial (SSH key issues) - Network failure (firewall blocking git:// protocol) - Authentication failure (private repos without credentials) - Directory creation issues (permissions) The --mirror flag creates a bare repository clone used internally by npm for caching, and failure indicates the underlying Git operation could not complete.
Typical symptoms
- npm install or npm ci fails with 'npm ERR! code 128'
- Error message includes 'git clone --mirror -q' followed by a fatal error
- 'Permission denied (publickey)' message appears in error output
- 'fatal: Could not read from remote repository' in logs
- Installation works on one machine but fails on another (SSH vs HTTPS)
Common causes
- SSH keys not configured or missing on the system (for private repos)
- GitHub SSH key revoked, expired, or removed from account
- SSH key has a passphrase but no ssh-agent running
- Network firewall or proxy blocking SSH port 22
- Repository URL uses SSH but system only has HTTPS access
- Private repository authentication credentials missing
- Insufficient file system permissions for npm cache directories
- Git version incompatible or git command not in PATH
How to fix "npm ERR! code 128 npm ERR! git clone --mirror git://github.com/user/repo.git failed with code 128"
First, clear the npm cache which may contain corrupted Git clone attempts:
npm cache clean --forceThen verify Git is installed and working:
git --version
git config --listIf Git isn't in your PATH, install or reinstall Git.
If your package.json contains git+ssh dependencies, ensure SSH keys are properly configured:
# List SSH keys
ls -la ~/.ssh/
# If no key exists, generate one
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -N ""
# Display public key to add to GitHub
cat ~/.ssh/id_ed25519.pubThen add the public key to GitHub Settings > SSH and GPG keys.
Start the SSH agent and add your key:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519Manually verify you can access the repository:
For SSH:
ssh -vvv git@github.comFor HTTPS:
git clone https://github.com/user/repo.gitIf this fails, the issue is with your Git/SSH setup, not npm.
Corporate firewalls often block SSH port 22. Configure Git to rewrite SSH URLs to HTTPS:
# Convert SSH URLs to HTTPS
git config --global url."https://github.com/".insteadOf git+ssh://git@github.com
git config --global url."https://github.com/".insteadOf git@github.com:
git config --global url."https://".insteadOf git://Then retry:
npm cache clean --force
npm installFor private repositories, HTTPS with a token is more reliable:
1. Generate a personal access token on GitHub (Settings > Developer settings)
2. Update package.json with HTTPS format:
{
"dependencies": {
"my-package": "git+https://<TOKEN>:x-oauth-basic@github.com/user/repo.git"
}
}Or use .npmrc to configure the token globally.
Sometimes package-lock.json contains stale references:
rm package-lock.json
rm -rf node_modules/
npm cache clean --force
npm installThis forces npm to re-evaluate all dependencies and use the current URL format.
Advanced notes
Debugging Details: The --mirror flag creates a bare repository in npm's cache (~/.npm/_cacache) to avoid re-cloning the same commit. Exit code 128 is generic; check debug logs at ~/.npm/_logs/ for the actual Git error.
URL Format Nuances:
- git+ssh requires SSH key: git+ssh://git@github.com:user/repo.git
- git+https requires network access and optional token
- Bare git:// protocol (port 9418) is disabled on most Git hosts for security
Docker/CI environments: SSH keys never leave host; use --ssh flag in Docker rather than copying keys. For CI, prefer HTTPS with tokens.
Frequently asked questions
- What does "npm ERR! code 128 npm ERR! git clone --mirror git://github.com/user/re" mean?
- Exit code 128 is a fatal Git error that occurs when npm fails to clone a repository during dependency installation. This typically happens when npm runs "git clone --mirror" to cache a Git-based dependency. The error indicates that Git encountered an unrecoverable problem such as: - Permission denial (SSH key issues) - Network failure (firewall blocking git:// protocol) - Authentication failure (private repos without credentials) - Directory creation issues (permissions) The --mirror flag creates a bare repository clone used internally by npm for caching, and failure indicates the underlying Git operation could not complete.
- How do I fix "npm ERR! code 128 npm ERR! git clone --mirror git://github.com/user/re"?
- Exit code 128 is a fatal Git error that occurs when npm fails to clone a repository during dependency installation. This typically happens when Git encounters permission denial, network failure, or authentication issues.
- What causes "npm ERR! code 128 npm ERR! git clone --mirror git://github.com/user/re"?
- SSH keys not configured or missing on the system (for private repos) GitHub SSH key revoked, expired, or removed from account SSH key has a passphrase but no ssh-agent running
- Is the "npm ERR! code 128 npm ERR! git clone --mirror git://github.com/user/re" 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: Git URLs as dependencies(Official Docs)
- ๐GitHub: npm issues(GitHub)
- ๐ฌSO: npm git dependencies(Stack Overflow)