How to fix npm ERR! code ENOENT npm ERR! tar: Invalid tar file in npm

npmINTERMEDIATEMEDIUMUpdated Dec 5, 2025· 121 views

The 'Invalid tar file' error occurs when npm fails to extract a downloaded package because the tar archive is corrupted, incomplete, or in an unrecognized format. This typically happens during npm install when a package download was interrupted or the cache contains damaged files.

Quick fix

Fixes npm ERR! code ENOENT npm ERR! tar: Invalid tar file

npm cache clean --force
  1. Clear npm cache
  2. Delete lock file and node_modules
  3. Reinstall dependencies
  4. Update npm and Node.js
npm — error
npm cache clean --force
npm ERR! code ENOENT
npm ERR! tar: Invalid tar file

What this error means

The "Invalid tar file" error occurs when npm fails to extract a downloaded package because the tar archive is corrupted, incomplete, or in an unrecognized format. This typically happens during the npm install process when npm downloads a package from the registry, caches it, and attempts to extract it into node_modules. The tar archive may be damaged due to network interruptions, corrupted cache, checksum mismatches, or registry issues. npm uses the tar package internally to handle gzip decompression and archive extraction. When downloading a package, npm performs an integrity check by comparing the downloaded file's SHA-512 hash against the value in package-lock.json. If hashes don't match or the archive header is malformed, extraction fails.

Typical symptoms

  • Installation halts with tar extraction errors (TAR_BAD_ARCHIVE, TAR_ENTRY_INVALID)
  • npm WARN tar messages repeated for multiple dependencies
  • Checksum verification failures in package-lock.json
  • 'Tarball data seems to be corrupted. Trying one more time' warnings
  • Some packages install while others fail
  • Error occurs consistently even on clean install attempts

Common causes

  1. Partial/interrupted downloads leaving truncated .tgz files
  2. Corrupted npm cache from previous failed installations
  3. Checksum mismatches between package-lock.json and downloaded tarball
  4. Registry server issues serving corrupted tarballs
  5. Network proxy interference corrupting data during download
  6. Stale package-lock.json referencing old/missing versions
  7. Insufficient disk space during extraction

How to fix "npm ERR! code ENOENT npm ERR! tar: Invalid tar file"

1Clear npm cache

Remove all cached .tar.gz files and corrupt metadata:

bash
npm cache clean --force

This forces npm to re-download packages fresh on next install. If you prefer verification first, use:

bash
npm cache verify
2Delete lock file and node_modules

Remove both package-lock.json and the node_modules directory to eliminate stale references:

bash
rm -rf node_modules package-lock.json

On Windows:

cmd
rmdir /S /Q node_modules
del package-lock.json
3Reinstall dependencies

Run npm install to download all packages fresh and recreate the lock file:

bash
npm install

Watch for any tar errors that reappear—they'll help identify which specific package is problematic.

4Update npm and Node.js

Ensure you're running the latest stable versions:

bash
npm install -g npm@latest

Update Node.js via https://nodejs.org. Older versions have known tar extraction bugs that have been fixed in recent releases.

5Verify network stability

Check your internet connection by visiting https://registry.npmjs.org/ in a browser. If behind a corporate proxy or firewall, temporarily disable them to test.

Run with verbose output to see detailed download progress:

bash
npm install --verbose
6Check disk space

Verify you have sufficient free disk space:

bash
# macOS/Linux
df -h

# Windows
dir C:\

Package extraction needs temp space. If low on space, free up disk and retry.

7Isolate the problematic package

If errors persist, note which specific package fails from verbose output. Try installing just that package:

bash
npm install <package-name>@<version>

Report the issue on that package's GitHub repo if it consistently fails.

Advanced notes

Chunked encoding bug: Some npm registry proxies and older npm versions (< v7.20) have issues with HTTP chunked-transfer-encoding, causing partial downloads that appear valid but are actually truncated. Upgrading to npm 9.x+ and Node 16+ largely resolves this.

Private registry considerations: Private registries (Verdaccio, npm Enterprise, Artifactory) may serve corrupted tarballs if misconfigured. Test with curl to verify the registry can serve tarballs cleanly.

Caching strategy: npm v5+ uses "smart cache" that self-heals corruption, but aggressive caching across CI/CD environments can preserve corrupted files. Always use npm ci --prefer-offline in CI for more reproducible builds.

Frequently asked questions

What does "npm ERR! code ENOENT npm ERR! tar: Invalid tar file" mean?
The "Invalid tar file" error occurs when npm fails to extract a downloaded package because the tar archive is corrupted, incomplete, or in an unrecognized format. This typically happens during the npm install process when npm downloads a package from the registry, caches it, and attempts to extract it into node_modules. The tar archive may be damaged due to network interruptions, corrupted cache, checksum mismatches, or registry issues.
How do I fix "npm ERR! code ENOENT npm ERR! tar: Invalid tar file"?
The 'Invalid tar file' error occurs when npm fails to extract a downloaded package because the tar archive is corrupted, incomplete, or in an unrecognized format. This typically happens during npm install when a package download was interrupted or the cache contains damaged files.
What causes "npm ERR! code ENOENT npm ERR! tar: Invalid tar file"?
Partial/interrupted downloads leaving truncated .tgz files Corrupted npm cache from previous failed installations Checksum mismatches between package-lock.json and downloaded tarball
Is the "npm ERR! code ENOENT npm ERR! tar: Invalid tar file" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading