npm / cli

the package manager for JavaScript
https://docs.npmjs.com/cli/
Other
8.5k stars 3.19k forks source link

[BUG] npm fails install of any packages - TAR_BAD_ARCHIVE #7893

Closed gsario closed 2 weeks ago

gsario commented 2 weeks ago

Is there an existing issue for this?

This issue exists in the latest npm version

Current Behavior

npm fails to install any packages, downloading any dependency related to eslint causes TAR_BAD_ARCHIVE error.

Here's what I tried:

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:

7097 http fetch GET 304 https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz 864ms (cache skip)
7098 warn tar TAR_BAD_ARCHIVE: Unrecognized archive format
7099 silly tar Error: TAR_BAD_ARCHIVE: Unrecognized archive format
7099 silly tar     at Unpack.warn (/usr/local/lib/node_modules/npm/node_modules/tar/lib/warn-mixin.js:21:40)
7099 silly tar     at Unpack.warn (/usr/local/lib/node_modules/npm/node_modules/tar/lib/unpack.js:236:18)
7099 silly tar     at Unpack.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/tar/lib/parse.js:83:14)
7099 silly tar     at Unpack.emit (node:events:530:35)
7099 silly tar     at [emit] (/usr/local/lib/node_modules/npm/node_modules/tar/lib/parse.js:313:12)
7099 silly tar     at [maybeEnd] (/usr/local/lib/node_modules/npm/node_modules/tar/lib/parse.js:468:17)
7099 silly tar     at [consumeChunk] (/usr/local/lib/node_modules/npm/node_modules/tar/lib/parse.js:476:21)
7099 silly tar     at Unpack.write (/usr/local/lib/node_modules/npm/node_modules/tar/lib/parse.js:427:25)
7099 silly tar     at Unpack.end (/usr/local/lib/node_modules/npm/node_modules/tar/lib/parse.js:548:14)
7099 silly tar     at Pipe.end (/usr/local/lib/node_modules/npm/node_modules/minipass/dist/commonjs/index.js:116:23) {
7099 silly tar   recoverable: false,
7099 silly tar   cwd: '/Users/gevorg.sargsyan/Projects/dev/js/fireship-memento/node_modules/fast-deep-equal',
7099 silly tar   code: 'TAR_BAD_ARCHIVE',
7099 silly tar   tarCode: 'TAR_BAD_ARCHIVE'
7099 silly tar }
7146 silly packumentCache corgi:https://registry.npmjs.org/@svgr%2fwebpack cache-miss
7147 http fetch GET 200 https://registry.npmjs.org/@svgr%2fwebpack 68ms (cache hit)
7148 silly packumentCache corgi:https://registry.npmjs.org/@svgr%2fwebpack set size:85201 disposed:false
7149 warn deprecated workbox-core@6.6.1: this package has been deprecated
7150 warn deprecated workbox-core@6.6.1: this package has been deprecated
7151 warn deprecated workbox-core@6.6.1: this package has been deprecated
7152 warn deprecated eslint@8.57.1: This version is no longer supported. Please see https://eslint.org/version-support for other options.
7153 verbose stack Error: TAR_BAD_ARCHIVE: Unrecognized archive format
7153 verbose stack     at Unpack.warn (/usr/local/lib/node_modules/npm/node_modules/tar/lib/warn-mixin.js:21:40)
7153 verbose stack     at Unpack.warn (/usr/local/lib/node_modules/npm/node_modules/tar/lib/unpack.js:236:18)
7153 verbose stack     at Unpack.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/tar/lib/parse.js:83:14)
7153 verbose stack     at Unpack.emit (node:events:530:35)
7153 verbose stack     at [emit] (/usr/local/lib/node_modules/npm/node_modules/tar/lib/parse.js:313:12)
7153 verbose stack     at [maybeEnd] (/usr/local/lib/node_modules/npm/node_modules/tar/lib/parse.js:468:17)
7153 verbose stack     at [consumeChunk] (/usr/local/lib/node_modules/npm/node_modules/tar/lib/parse.js:476:21)
7153 verbose stack     at Unpack.write (/usr/local/lib/node_modules/npm/node_modules/tar/lib/parse.js:427:25)
7153 verbose stack     at Unpack.end (/usr/local/lib/node_modules/npm/node_modules/tar/lib/parse.js:548:14)
7153 verbose stack     at Pipe.end (/usr/local/lib/node_modules/npm/node_modules/minipass/dist/commonjs/index.js:116:23)
7154 error code TAR_BAD_ARCHIVE
7155 error TAR_BAD_ARCHIVE: Unrecognized archive format
7156 silly unfinished npm timer reify 1730736384828
7157 silly unfinished npm timer reify:unpack 1730736388377
7158 silly unfinished npm timer reifyNode:node_modules/fast-deep-equal 1730736388382

Expected Behavior

The packages should be installed, and .tgz archives normally downloaded.

Steps To Reproduce

No response

Environment

Arxtage commented 2 weeks ago

I had a similar issue getting 304 with fast-deep-equal on public wifi, which was fixed after I switched to different wifi. Not sure if this will help, but worth giving a try:)

gsario commented 2 weeks ago

Fixed using Claude.

  1. Cleared npm cache completely:

    rm -rf ~/.npm
    mkdir ~/.npm
  2. Installed the latest eslint globally:

    npm install -g eslint@latest
skuill commented 2 weeks ago

Thank you @Arxtage! Changing Wi-Fi really helped right away. I don’t know what kind of magic is hidden behind this.. image

Verbinmay commented 2 weeks ago

I don’t understand what kind of magic it is, but I’ve been looking for an answer to this problem for two days, but it was solved by changing Wi-Fi

Grach90 commented 2 weeks ago

I had a similar issue getting 304 with fast-deep-equal on public wifi, which was fixed after I switched to different wifi. Not sure if this will help, but worth giving a try:)

Thank you very much @Arxtage for solution!!