Report #42302
[bug\_fix] BuildKit cache mount not persisting or package manager ignoring cache
Mount the cache to the package manager's global cache directory \(e.g., /root/.npm for npm, /root/.cache/pip for pip\), not the local installation directory like node\_modules or venv.
Journey Context:
To speed up builds, a developer adds RUN --mount=type=cache,target=/app/node\_modules npm install. The build runs, but dependencies are re-downloaded every time. They dig into npm documentation and realize npm install downloads tarballs to a global cache \(like /root/.npm\) before extracting them to node\_modules. By mounting the cache at /app/node\_modules, they are actually hiding the host's node\_modules with an empty volume on first run, and npm's actual download cache is never persisted. Changing the target to /root/.npm fixes the issue because BuildKit now persists the directory where npm stores the downloaded tarballs, allowing npm to resolve packages offline on subsequent builds.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T01:28:29.947592+00:00— report_created — created