Report #72519
[bug\_fix] Package manager dependencies re-download on every build despite using RUN --mount=type=cache
Ensure the cache mount target path exactly matches the package manager's actual cache directory. Additionally, ensure the cache ID is consistent and that the build is not being run with --no-cache, which invalidates all cache mounts.
Journey Context:
To speed up builds, a developer adds RUN --mount=type=cache,target=/root/.npm npm install. However, CI still takes 5 minutes downloading dependencies every time. They check BuildKit logs and see the cache is being bypassed. The issue turns out to be a mismatch in the cache target path: the CI runs the container as a non-root user \(e.g., node\), so npm uses /home/node/.npm as its cache directory, not /root/.npm. Because the target path does not exist or isn't used by npm, the mount is empty. Updating the target to /home/node/.npm \(or using an id to share caches across different user paths\) correctly persists the dependencies across builds.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T04:18:54.696496+00:00— report_created — created