How to fix npm ERR! code EBADTAR npm ERR! Invalid tarball format in npm
The EBADTAR error indicates npm encountered a corrupted or invalid tarball during package installation. This is typically caused by cache corruption, network issues, or proxy problems.
Quick fix
Fixes npm ERR! code EBADTAR npm ERR! Invalid tarball format
# Remove dependencies and lock file
rm -rf node_modules package-lock.json
# Clear npm cache completely
npm cache clean --force
# Verify cache integrity
npm cache verify
# Reinstall
npm install- Clear npm cache and reinstall
- Run verbose install to identify failing package
- Check npm and registry configuration
- Increase timeout and retry settings
# Remove dependencies and lock filerm -rf node_modules package-lock.json# Clear npm cache completelynpm cache clean --force# Verify cache integritynpm cache verify# Reinstallnpm installnpm ERR! code EBADTARnpm ERR! Invalid tarball format
What this error means
This error occurs when npm downloads a package tarball (.tgz file) that's either corrupted, incomplete, or in an unexpected format. The tarball is the compressed archive that contains the package code. Common scenarios include: interrupted downloads leaving partial files in cache, network corruption during transfer, proxy servers re-encoding files incorrectly, or registry issues serving invalid content.
Typical symptoms
- npm install fails partway through dependency resolution
- Specific packages fail while others succeed
- Works on different machine or network
- Error persists even after retry attempts
- Related warnings about TAR_ENTRY_INVALID or checksum failure
Common causes
- Corrupted npm cache from interrupted downloads
- Network corruption during package download
- Proxy server intercepting or re-encoding tarballs
- Registry serving invalid or incomplete files
- Antivirus software modifying downloaded files
- Disk I/O errors during extraction
How to fix "npm ERR! code EBADTAR npm ERR! Invalid tarball format"
Start with the most effective fix:
# Remove dependencies and lock file
rm -rf node_modules package-lock.json
# Clear npm cache completely
npm cache clean --force
# Verify cache integrity
npm cache verify
# Reinstall
npm installFind exactly which package is corrupted:
npm install --verbose
# Even more detailed
npm install --loglevel=sillyLook for lines like:
npm WARN tar TAR_BAD_ARCHIVE: Unrecognized archive format for package-name@1.0.0Verify correct registry settings:
# Check registry URL
npm config get registry
# Should be: https://registry.npmjs.org/
# Reset if wrong
npm config set registry https://registry.npmjs.org/
# Check for proxy issues
npm config get proxy
npm config get https-proxy
# Remove proxy if not needed
npm config delete proxy
npm config delete https-proxyFor slow or unreliable networks, increase tolerances:
Add to ~/.npmrc:
fetch-timeout=60000
fetch-retry-mintimeout=20000
fetch-retry-maxtimeout=120000
fetch-retries=5Then retry:
npm installEnsure sufficient disk space:
# Linux/macOS
df -h
# Need at least 1GB free
# If low, clean up:
npm cache clean --force
rm -rf node_modulesOlder npm versions have known tarball handling bugs:
# Update npm
npm install -g npm@latest
# Verify versions
node --version
npm --version
# Reinstall project
rm -rf node_modules package-lock.json
npm installAdvanced notes
For corporate environments with proxies, the proxy may be re-encoding tarballs incorrectly. Check with your IT team if Apache or nginx is configured with AddEncoding directives for .tgz files.
If using a private registry like Verdaccio or Nexus, verify it's properly proxying to npmjs.org. Test with: curl -I https://your-registry/package-name
For persistent issues with specific packages, try installing directly from npm: npm install package-name --registry https://registry.npmjs.org
Frequently asked questions
- What does "npm ERR! code EBADTAR npm ERR! Invalid tarball format" mean?
- tgz file) that's either corrupted, incomplete, or in an unexpected format. The tarball is the compressed archive that contains the package code. Common scenarios include: interrupted downloads leaving partial files in cache, network corruption during transfer, proxy servers re-encoding files incorrectly, or registry issues serving invalid content.
- How do I fix "npm ERR! code EBADTAR npm ERR! Invalid tarball format"?
- The EBADTAR error indicates npm encountered a corrupted or invalid tarball during package installation. This is typically caused by cache corruption, network issues, or proxy problems.
- What causes "npm ERR! code EBADTAR npm ERR! Invalid tarball format"?
- Corrupted npm cache from interrupted downloads Network corruption during package download Proxy server intercepting or re-encoding tarballs
- Is the "npm ERR! code EBADTAR npm ERR! Invalid tarball format" error serious?
- It is a medium-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐npm Official Documentation
- ๐package.json Documentation(Official Docs)
- ๐ฌStack Overflow: npm(Stack Overflow)
- ๐GitHub: npm(GitHub)