Skip to content
Latchkey

GitHub Actions Cache "Cannot open: File exists" / tar Extraction Failed

A cache restore fails during tar extraction with "Cannot open: File exists" because files already exist at the restore path - a prior step populated the directory, so the archive cannot overwrite into it.

What this error means

The cache restore step fails with tar errors like "Cannot open: File exists", usually because something created or restored files at the same path before the cache action extracted its archive.

Actions log
/usr/bin/tar: ./node_modules/.bin/x: Cannot open: File exists
/usr/bin/tar: Exiting with failure status due to previous errors
Warning: Failed to restore: ...

Common causes

Path already populated before restore

A step (an install, a checkout of vendored files, a second cache) created files at the cache path. tar then refuses to overwrite existing files during extraction.

Two cache steps target the same path

Restoring two caches into the same directory makes the second collide with files the first already wrote.

How to fix it

Restore before populating the path

Place the cache restore before any step that writes to that path, so extraction lands in a clean directory.

.github/workflows/ci.yml
- uses: actions/checkout@v4
- uses: actions/cache@v4        # restore FIRST, into an empty path
  with:
    path: node_modules
    key: deps-${{ hashFiles('package-lock.json') }}
- run: npm ci                   # then populate / reconcile

Avoid overlapping cache paths

  1. Do not restore two caches into the same directory.
  2. Clear or use a clean directory before restoring if an earlier step must populate it.
  3. If a tool must write first, cache a different, non-overlapping path.

How to prevent it

  • Restore caches before steps that write to the same path.
  • Keep each cache pointed at a distinct, non-overlapping directory.
  • Avoid restoring into a directory another step already populated.

Frequently asked questions

What causes ""Cannot open: File exists""?
A step (an install, a checkout of vendored files, a second cache) created files at the cache path. tar then refuses to overwrite existing files during extraction.
How do I fix "Cannot open: File exists"?
Place the cache restore before any step that writes to that path, so extraction lands in a clean directory.
Can Latchkey fix this automatically?
Yes. Latchkey runs your GitHub Actions on managed runners that detect this failure, apply the fix, and retry the job automatically - self-healing is on by default.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card