Skip to content
Latchkey

Docker build context "Filename too long" on Windows in CI

On a Windows runner, Git fails to write deep paths during checkout because of the 260-character MAX_PATH limit, so the build context the Docker build needs is never fully on disk. The error comes from Git, before docker build runs.

What this error means

On a Windows runner, the checkout step fails with "error: unable to create file X: Filename too long" or "cannot create directory at X: Filename too long", and the later Docker build cannot find expected files.

git
error: unable to create file node_modules/.../deeply/nested/path/index.js: Filename too long
fatal: cannot create directory at 'node_modules/.../deeply/nested': Filename too long

Common causes

Windows MAX_PATH limit on deep trees

A directory tree (often node_modules or vendored dependencies) exceeds 260 characters, so Git cannot create the file on Windows.

A long checkout directory plus deep paths

A long workspace path combined with deep repository paths pushes the total over the limit during checkout.

How to fix it

Enable Git long path support

Allow Git to use long paths on the runner before checkout.

Terminal
git config --system core.longpaths true

Shorten the tree or exclude it from context

  1. Use a short checkout directory to reserve path budget.
  2. Exclude deep generated trees like node_modules via .dockerignore.
  3. Build the dependency install inside the image instead of copying a deep tree.
.dockerignore
node_modules
**/.cache

How to prevent it

  • Set core.longpaths true on Windows runners.
  • Keep workspace and repository paths short.
  • Exclude deep generated directories from the build context.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →