FG
💻 Software🛠️ Developer ToolsMicrosoft

[BUG] npm fails install of any packages - TAR_BAD_ARCHIVE

Fresh3 days ago
Mar 14, 20260 views
Confidence Score55%
55%

Problem

Is there an existing issue for this? - [X] I have searched the existing issues This issue exists in the latest npm version - [X] I am using the latest npm Current Behavior `npm` fails to install any packages, downloading any dependency related to `eslint` causes `TAR_BAD_ARCHIVE` error. Here's what I tried: - clean npm caches - doesn't help! - `npm audit verify` , `npm audit fix`, `npm audit fix --force` - delete & reinstall npm (various attempts with various protocols for deletion and installation) - tried to disable `eslint`, but react app creation scripts contain it by default - tried to upgrade `eslint` version, but I get the same `TAR_BAD_ARCHIVE` when `eslint` is being installed Here are the failed downloads from the logs after running `npm install`, `npm init @eslint/config@latest` or any other package install that has dependencies on `eslint`: [code block] [code block] Expected Behavior The packages should be installed, and .tgz archives normally downloaded. Steps To Reproduce _No response_ Environment - npm: 10.9.0 - Node.js: v22.11.0 - OS Name: MacOS Sonoma 14.5

Error Output

Error: TAR_BAD_ARCHIVE: Unrecognized archive format

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix TAR_BAD_ARCHIVE Error in npm Package Installation

Medium Risk

The TAR_BAD_ARCHIVE error typically occurs when npm attempts to extract a corrupted or improperly formatted tarball (.tgz file) during package installation. This can happen due to network issues, corrupted cache, or problems with the npm registry. In this case, the issue seems to be related to the ESLint package and its dependencies, which may be causing the installation process to fail.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Clear npm Cache

    Even though you have tried cleaning the npm cache, it is crucial to ensure that the cache is completely cleared to remove any corrupted files. Use the following command to clean the cache thoroughly.

    bash
    npm cache clean --force
  2. 2

    Check Network Configuration

    Ensure that your network configuration is not causing issues with npm. Sometimes, proxies or firewalls can interfere with package downloads. If you are behind a proxy, configure npm to use it with the following command:

    bash
    npm config set proxy http://your-proxy-url:port
    npm config set https-proxy http://your-proxy-url:port
  3. 3

    Reinstall Node.js and npm

    Completely uninstall Node.js and npm to ensure there are no residual files causing issues. After uninstalling, reinstall Node.js which includes npm. Use a version manager like nvm for easier management.

    bash
    nvm uninstall v22.11.0
    nvm install v22.11.0
  4. 4

    Install ESLint Directly

    Try installing ESLint directly to see if the issue persists. This can help isolate whether the problem is with ESLint or the npm installation process.

    bash
    npm install eslint@latest
  5. 5

    Use a Different Registry

    If the problem continues, try switching to a different npm registry. Sometimes, the default registry may have issues. You can use the following command to switch to the Yarn registry as an alternative.

    bash
    npm config set registry https://registry.yarnpkg.com

Validation

To confirm the fix worked, attempt to install a package that previously failed with the TAR_BAD_ARCHIVE error. If the installation completes successfully without errors, the issue is resolved. Additionally, check the npm cache and logs for any further errors.

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

npmpackage-managernodejsbugneeds-triage