67

I'm trying to install IPFS from herenpm install ipfs --save and it is giving me the error as

npm ERR! tar.unpack error reading /media/FLASH/Tech/IPFS/ipfs

npm ERR! addLocal Could not install /media/FLASH/Tech/IPFS/ipfs

npm ERR! Linux 4.15.0-29-generic

npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "ipfs" "--save"

npm ERR! node v6.9.2

npm ERR! npm v3.10.9

npm ERR! 0-byte tarball

npm ERR! Please run npm cache clean

I tried doing npm cache clean but still it is giving me the same error while doing npm install ipfs --save

I don't know why I'm getting this error. and how to avoid this error.

FLASH
  • 981
  • 2
  • 8
  • 11
  • You've not given us much information. What is your question, do you want to understand why this is happening or how to get the installation to pass? If you want to get the installation to pass, I'd suggest doing as npm says and run `npm cache clean` to begin with. – Elliot Blackburn Jul 31 '18 at 07:19
  • 1
    Yes. I did run ``npm cache clean`` and i tried ```npm install ipfs``` again but still it is giving the same error. I don't know why this is giving the error. – FLASH Jul 31 '18 at 07:26
  • You should add that to your original question so people can clearly see the problem. – Elliot Blackburn Jul 31 '18 at 07:27

4 Answers4

120

As of npm@5, the npm cache self-heals from corruption issues and data extracted from the cache is guaranteed to be valid. If you want to make sure everything is consistent, use npm cache verify instead. On the other hand, if you're debugging an issue with the installer, you can use npm install --cache /tmp/empty-cache to use a temporary cache instead of nuking the actual one.

If you're sure you want to delete the entire cache, rerun:

npm cache clean --force

A complete log of this run can be found in /Users/USERNAME/.npm/_logs/2019-01-08T21_29_30_811Z-debug.log.

double-beep
  • 5,031
  • 17
  • 33
  • 41
infin80
  • 1,343
  • 1
  • 9
  • 10
  • 2
    `npm cache clean` no longer works because npm is self healing. The documentation says to instead run `npm cache verify` if you think there is an issue – Darrow Hartman Jun 26 '21 at 02:12
  • 1
    Thanks, I am using this `npm install --cache /tmp/npm-cache-$(date +"%Y%m%d_%H%M%S")` now. – John Xiao Dec 04 '21 at 14:00
  • 2
    For reference: [npm cache docs](https://docs.npmjs.com/cli/v8/commands/npm-cache) mention: "it should never be necessary to clear the cache for any reason other than **reclaiming disk space**, thus why clean now requires `--force` to run" and recommend `npm cache verify` for integrity/cleaning up. – CPHPython Jun 08 '22 at 11:20
7

This error can be due to many many things.

The key here seems the hint about error reading. I see you are working on a flash drive or something similar? Try to run the install on a local folder owned by your current user.

You could also try with sudo, that might solve a permission problem if that's the case.

Another reason why it cannot read could be because it has not downloaded correctly, or saved correctly. A little problem in your network could have caused that, and the cache clean would remove the files and force a refetch but that does not solve your problem. That means it would be more on the save part, maybe it didn't save because of permissions, maybe it didn't not save correctly because it was lacking disk space...

Salketer
  • 14,263
  • 2
  • 30
  • 58
6

npm cache clean doesn't work now

Type below command :-

1- npm cache verify

Read the error in terminal it will show you exact commands to run for solution. you might need to append --force

2- sudo chown -R 501:20 "/$path$/.npm". (this works for me )

rap-2-h
  • 30,204
  • 37
  • 167
  • 263
user2830254
  • 61
  • 1
  • 2
0

To clean the npm cache on your system, you should run the npm cache clean command. This will purge any cached packages and modules from the local npm cache folder.

Clearing out the cache can help resolve certain npm errors or inconsistencies, and also frees up disk space by removing redundant packages that have accumulated over time.

For a step-by-step guide on how to use the npm cache clean command, I recommend checking out this handy tutorial: npm clear cache.

It covers the full syntax and provides useful examples of cleaning the npm cache. The tutorial also explains some best practices around when you may want to clear the local cache.

Let me know if running npm cache clean helps resolve the issue you are running into. That TeachingBee article should give you a good overview of how to leverage the command.

Hiten
  • 1