How to fix npm ERR! code 128 npm ERR! git clone --mirror git://github.com/user/repo.git failed with code 128 in npm

npmINTERMEDIATEHIGHUpdated Dec 5, 2025ยท 330 views

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
  1. Clear npm cache and verify Git is working
  2. Check and fix SSH key configuration
  3. Test Git access to the repository
  4. Switch from SSH to HTTPS if SSH is blocked
npm โ€” error
npm cache clean --force
npm ERR! code 128
npm 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

  1. SSH keys not configured or missing on the system (for private repos)
  2. GitHub SSH key revoked, expired, or removed from account
  3. SSH key has a passphrase but no ssh-agent running
  4. Network firewall or proxy blocking SSH port 22
  5. Repository URL uses SSH but system only has HTTPS access
  6. Private repository authentication credentials missing
  7. Insufficient file system permissions for npm cache directories
  8. 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"

1Clear npm cache and verify Git is working

First, clear the npm cache which may contain corrupted Git clone attempts:

bash
npm cache clean --force

Then verify Git is installed and working:

bash
git --version
git config --list

If Git isn't in your PATH, install or reinstall Git.

2Check and fix SSH key configuration

If your package.json contains git+ssh dependencies, ensure SSH keys are properly configured:

bash
# 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.pub

Then add the public key to GitHub Settings > SSH and GPG keys.

Start the SSH agent and add your key:

bash
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
3Test Git access to the repository

Manually verify you can access the repository:

For SSH:

bash
ssh -vvv git@github.com

For HTTPS:

bash
git clone https://github.com/user/repo.git

If this fails, the issue is with your Git/SSH setup, not npm.

4Switch from SSH to HTTPS if SSH is blocked

Corporate firewalls often block SSH port 22. Configure Git to rewrite SSH URLs to HTTPS:

bash
# 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:

bash
npm cache clean --force
npm install
5Use HTTPS with authentication token for private repos

For 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:

json
{
  "dependencies": {
    "my-package": "git+https://<TOKEN>:x-oauth-basic@github.com/user/repo.git"
  }
}

Or use .npmrc to configure the token globally.

6Delete package-lock.json and regenerate

Sometimes package-lock.json contains stale references:

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

This 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