DEV Community

CHANDAN HM
CHANDAN HM

Posted on

npm WARN tar TAR_ENTRY_INVALID checksum failure npm WARN tar

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: C:\Users\Chandan\AppData\Local\npm-cache_logs\2024-04-01T08_38_48_500Z-debug-0.log

To resolve this!

The error message you're encountering, specifically TAR_BAD_ARCHIVE: Unrecognized archive format, indicates that npm is encountering an issue with the format of an archive file during the installation process. This could be due to various reasons, including corrupted files, network interruptions during download, or issues with the npm cache.

Here are some steps you can take to try and resolve this issue:

Clear npm Cache: Clearing the npm cache might help in case there's a corrupted cache causing the issue. Run the following command:

npm cache clean --force
Retry Installation: Sometimes, simply retrying the installation process can resolve the issue, especially if it was caused by a temporary network glitch or other transient problem.

Verify Network Connection: Ensure that your internet connection is stable and there are no network interruptions during the installation process. You can try downloading the package manually using a web browser to verify if the package is accessible.

Check Filesystem: Ensure that there are no issues with your filesystem that could be causing problems with file operations. Make sure you have enough disk space available.

Inspect the Debug Log: Look into the debug log mentioned in the error message (C:\Users\Chandan\AppData\Local\npm-cache_logs\2024-04-01T08_38_48_500Z-debug-0.log). It may contain more specific information about what went wrong, which could help diagnose the problem further.

Use a Different npm Registry: Sometimes, issues can arise from the npm registry itself. You can try switching to a different npm registry to see if that resolves the problem. You can do this by running:

npm config set registry https://registry.npmjs.org/
Upgrade npm: Ensure that you're using the latest version of npm. You can update npm globally by running:

npm install -g npm@latest
If none of these steps resolve the issue, you may need to provide more specific details about your environment, the package you're trying to install, and any other relevant information to further diagnose the problem. Additionally, seeking support from the npm community forums or opening an issue on the npm GitHub repository might provide further assistance.

If this didn't worked means!
my npm install doesn't work after I reinstall the Node and clean the cache. It shows below: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 No idea what to do now.
So here is the issues

# 👇 remove node_modules and package-lock.json
rm -rf node_modules package-lock.json

# 👇 Clear and verify npm cache
npm cache clean --force
npm cache verify

# 👇 now run npm install again
npm install
Enter fullscreen mode Exit fullscreen mode

When you run the npm install command, npm will look for the packages listed as dependencies in your package.json file to download and install.

When you have a package-lock.json file in the directory, then npm will compare the checksum of the downloaded tarball .tgz file with the one found in your lock file.

Just remove the proxy in package.json

Top comments (3)

Collapse
 
manjeet8562 profile image
Manjeet Sharma

In my case i was using dockerfile to build and i had the same issue TAR_BAD_ARCHIVE: Unrecognized archive format

I have just added this:

RUN npm config set registry https://registry.npmmirror.com/ --global

before

npm install

it worked for me :)

Collapse
 
aniket_bansod_004 profile image
Aniket bansod

Thank you so much, your solution worked for me too.