I’m facing archive format errors when trying to install packages in my project. Already tried clearing the npm cache and updating to the newest npm version but nothing helped. The weird thing is that global installs work fine and other projects on my computer don’t have this issue. It only happens in this specific project.
npm install lodash
npm WARN tar TAR_ENTRY_INVALID checksum failure
npm WARN tar TAR_ENTRY_INVALID checksum failure
npm WARN tar TAR_ENTRY_INVALID checksum failure
npm WARN tar TAR_BAD_ARCHIVE: Unrecognized archive format
npm ERR! code TAR_BAD_ARCHIVE
npm ERR! TAR_BAD_ARCHIVE: Unrecognized archive format
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Developer\AppData\Local\npm-cache\_logs\2021-02-14T23_15_42_891Z-debug.log
When I run the verbose install command, I can see it’s having trouble with the tar extraction process. The logs show checksum validation failures and then it fails completely with the unrecognized archive format error. Has anyone seen this before and knows how to fix it?
This looks like a corrupted registry response or network interruption during download. I’ve hit this exact error when my antivirus was affecting npm’s tar extraction. Try disabling real-time protection temporarily while installing to see if that resolves the issue. Another solution that worked for me was switching registries with npm install --registry https://registry.npmjs.org/ to force a fresh download. Since this problem is project-specific, something in your local setup might be corrupting downloads for that directory. Additionally, check if your project folder is on a network drive or has unusual permissions, as I’ve seen both lead to similar issues during extraction.
It appears you are dealing with a project-specific issue rather than a broader npm problem. I encountered a similar situation previously where corrupt cache files in the node_modules directory caused persistent errors despite clearing the cache. I recommend deleting the entire node_modules folder and the package-lock.json file, then reinstalling with a fresh npm install. This ensures that references to corrupted packages in the lockfile are removed. If the issue persists, consider checking for problems related to network drives or file permissions that could interfere with extraction. Additionally, using npm install --no-optional could help bypass any optional dependencies that may be contributing to the errors.
Had this exact problem six months ago - turned out to be filesystem corruption in my project directory. TAR_ENTRY_INVALID errors usually mean npm’s getting bad archive data, but since your global installs work fine, it’s probably your project’s local environment. Try running npm install from a totally different location first to see if it’s the project folder itself. I had to copy all my source files to a new directory and reinitialize npm there. Also check your disk space and run a filesystem check. Low disk space causes partial downloads that mess up archive formats. Since it’s only happening in this project, it’s almost definitely a local filesystem issue, not network or npm config problems.
The Problem:
You’re encountering TAR_BAD_ARCHIVE errors during npm install, indicating that npm is unable to properly extract downloaded package archives. This happens only in a specific project, while global installs work fine. The error messages show checksum failures and ultimately an “unrecognized archive format.” This points to a problem with the local project environment, not a system-wide npm issue.
Understanding the “Why” (The Root Cause):
The TAR_BAD_ARCHIVE error usually means that the downloaded package archive is corrupted or incomplete. Since the problem is isolated to one project, the issue likely lies within that project’s directory or its associated files. Corrupted cache files, file system errors, insufficient disk space, network interruptions during download, antivirus interference, or incorrect proxy settings can all lead to this. The original answer suggests that npm might get into a “bizarre state” requiring a complete refresh.
Step-by-Step Guide:
- Completely Remove and Reinstall Packages: The most effective solution is a clean reinstall, eliminating any potentially corrupted packages or lock files. This involves deleting the
node_modules folder and the package-lock.json file, then reinstalling all dependencies. Use the following commands:
rm -rf node_modules package-lock.json
npm install --verbose --no-audit
The --verbose flag provides detailed output, helping to pinpoint any further issues during installation. The --no-audit flag skips the security audit, speeding up the process. If the problem persists after this, move to step 2.
- Check for and Resolve Potential Conflicts: Examine any of these factors that could be interfering with the package installation process:
-
Antivirus Software: Temporarily disable real-time protection from your antivirus software. Sometimes, antivirus interferes with the download and extraction process. Re-run npm install after disabling.
-
Proxy Settings: If you’re behind a corporate proxy, verify that it’s correctly configured and doesn’t block tar files or npm’s access to the registry. Try setting the registry explicitly:
npm config set registry https://registry.npmjs.org
-
Network Drive or Unusual Permissions: Check if your project folder resides on a network drive. Network drives can sometimes have performance issues leading to partial downloads. Similarly, unusual file permissions can cause problems. Move the project to a local drive or ensure the project directory has the correct permissions (read, write, execute) for the user account running npm.
-
Filesystem Corruption: Run a filesystem check utility specific to your operating system to detect and repair any potential corruption (e.g., chkdsk on Windows, fsck on Linux/macOS). A corrupted file system can lead to incomplete downloads and checksum mismatches.
-
Disk Space: Ensure you have sufficient free disk space. Low disk space can cause partial downloads, resulting in corrupted packages.
Common Pitfalls & What to Check Next:
If you still face issues after following these steps, consider:
-
Inspect the npm debug log: The error message provides a path to a debug log (C:\Users\Developer\AppData\Local\npm-cache\_logs\2021-02-14T23_15_42_891Z-debug.log). This log contains detailed information about the npm installation process, providing further clues about the problem.
-
Try a different registry: Besides https://registry.npmjs.org, you can try alternative npm registries, such as those offered by Verdaccio or private npm registries.
-
Consider alternative package managers: While less common, consider using alternative package managers like yarn or pnpm, which might have different handling for archive downloads.
Still running into issues? Share your (sanitized) config files, the exact command you ran, and any other relevant details. The community is here to help!
Same thing happened to me last month! My proxy settings were screwing with the downloads. Check if you’ve got corporate firewall or proxy stuff blocking tar files specifically. Also try npm config set registry https://registry.npmjs.org to reset the registry settings in that project folder.
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.