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.
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.
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 [email protected]For 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://[email protected]
git config --global url."https://github.com/".insteadOf [email protected]:
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>:[email protected]/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.
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://[email protected]: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.
npm ERR! code E401 npm ERR! 401 Unauthorized - Token has expired
Token has expired - npm authentication failure
npm ERR! code EAI_NODATA npm ERR! errno EAI_NODATA npm ERR! getaddrinfo EAI_NODATA registry.npmjs.org
How to fix "npm ERR! code EAI_NODATA - getaddrinfo EAI_NODATA"
npm ERR! code EMPTYPACKAGE npm ERR! Package contains no files
How to fix 'npm ERR! code EMPTYPACKAGE' - Package contains no files
npm ERR! code EWORKSPACEMISSING npm ERR! Workspace does not exist: packages/missing
How to fix "npm ERR! code EWORKSPACEMISSING - Workspace does not exist" error
npm ERR! code EADDRNOTAVAIL npm ERR! errno EADDRNOTAVAIL npm ERR! Address not available
How to fix "npm ERR! code EADDRNOTAVAIL - Address not available" error