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.
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 longCommon 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.
git config --system core.longpaths trueShorten the tree or exclude it from context
- Use a short checkout directory to reserve path budget.
- Exclude deep generated trees like
node_modulesvia.dockerignore. - Build the dependency install inside the image instead of copying a deep tree.
node_modules
**/.cacheHow to prevent it
- Set
core.longpaths trueon Windows runners. - Keep workspace and repository paths short.
- Exclude deep generated directories from the build context.