Exit code 128 in npm typically indicates a Git-related failure, usually SSH authentication issues when installing dependencies from Git repositories. Check SSH key configuration and Git access.
Exit code 128 is a Git-specific error code indicating that a Git operation failed during npm install. This commonly occurs when package.json includes dependencies hosted on Git repositories (using `git+ssh://` or `git+https://` URLs) and authentication fails. The most frequent cause is SSH key issues—either the SSH key isn't loaded, the SSH agent isn't running, or the key doesn't have access to the private repository. This error is especially common in CI/CD environments where SSH keys need explicit configuration.
The most common fix—ensure SSH agent is running with your key:
# Start SSH agent
eval "$(ssh-agent -s)"
# Add your SSH key
ssh-add ~/.ssh/id_rsa
# Or for newer ed25519 keys
ssh-add ~/.ssh/id_ed25519
# Verify key is loaded
ssh-add -lVerify SSH access to your Git provider:
# For GitHub
ssh -T [email protected]
# For GitLab
ssh -T [email protected]
# For Bitbucket
ssh -T [email protected]You should see a success message with your username.
If port 22 is blocked, switch to HTTPS:
# Configure Git to use HTTPS globally
git config --global url."https://".insteadOf git://
# For GitHub specifically
git config --global url."https://github.com/".insteadOf [email protected]:Reset npm state and reinstall:
# Clear npm cache
npm cache clean --force
# Remove lock file and modules
rm -rf node_modules package-lock.json
# Reinstall
npm installIn CI/CD environments, SSH keys need explicit setup:
GitHub Actions:
- uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}Docker:
# Mount SSH socket
docker run -v $SSH_AUTH_SOCK:/ssh-agent -e SSH_AUTH_SOCK=/ssh-agent ...
# Or use BuildKit secrets
RUN --mount=type=ssh npm installFor private repos in CI, use HTTPS with tokens instead of SSH:
# Configure Git to use token
git config --global url."https://${GITHUB_TOKEN}@github.com/".insteadOf "https://github.com/"
# Or update package.json to use HTTPS
"dependencies": {
"private-pkg": "https://${GITHUB_TOKEN}@github.com/org/repo.git"
}For large monorepos with many Git dependencies, npm may open too many concurrent SSH connections, causing failures. Reduce concurrency:
npm install --maxsockets=2On Windows with WSL, ensure you're using Linux SSH keys (generated within WSL) or properly mounting Windows SSH keys. The Windows and WSL file systems have different SSH key handling.
For corporate firewalls blocking port 22, configure SSH to use port 443:
# ~/.ssh/config
Host github.com
Hostname ssh.github.com
Port 443
User gitnpm notice access token expired or revoked. Please try logging in again.
Token has expired - npm authentication failure
npm ERR! code EAI_AGAIN
How to fix "EAI_AGAIN" in npm
npm error code E403 npm error 403 Forbidden - PUT https://registry.npmjs.org/<package>
How to fix 'E403 Forbidden' error in npm
npm ERR! code EUSAGE npm ERR! Usage error
How to fix "npm ERR! code EUSAGE" in Node.js projects
npm ERR! code E401 npm ERR! 401 Unauthorized
How to fix "E401 Unauthorized" in npm