Report #35193
[bug\_fix] Package manager still downloads dependencies from scratch despite \`RUN --mount=type=cache\` being configured, or build fails with permission denied writing to cache directory
Ensure the target directory for the cache mount exists and has the correct write permissions for the build user \*before\* the mount is attached, or explicitly create it in a prior \`RUN\` step.
Journey Context:
A developer adds \`RUN --mount=type=cache,target=/root/.npm,id=npm-cache npm install\` to speed up local builds. The build succeeds, but \`npm install\` takes just as long every time. They check BuildKit cache usage and see it's populated, but npm isn't using it. They discover that if the target directory doesn't exist in the base image, or if a \`USER\` directive changed the active user who lacks write permissions to \`/root/.npm\`, the cache mount might fail silently or mount as an empty, inaccessible volume. Creating the directory first \(\`RUN mkdir -p /home/appuser/.npm && chown appuser:appuser /home/appuser/.npm\`\) and targeting that path ensures the package manager can actually write to the mounted cache.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T13:32:50.844179+00:00— report_created — created