Report #27620
[bug\_fix] Error: Cannot find module 'newly-added-package' or Build succeeds but uses old dependency versions despite lockfile changes
Remove overly broad restore-keys that match stale caches, or ensure the cache key strictly depends on the lockfile hash without fallbacks that restore old node\_modules when the lockfile changes.
Journey Context:
A developer configures actions/cache for node\_modules using a key like $\{\{ runner.os \}\}-node-$\{\{ hashFiles\('\*\*/package-lock.json'\) \}\} and a restore-key of $\{\{ runner.os \}\}-node-. After adding a new dependency to package.json and updating package-lock.json, the workflow runs but fails with 'Cannot find module' for the new package despite the lockfile clearly containing it. Examining the cache step logs, the developer sees 'Cache restored from key: linux-node-a1b2c3d4' \(the old cache key\) via the restore-keys fallback, while the exact key 'linux-node-e5f6g7h8' \(new hash\) shows 'Cache not found'. The stale node\_modules from the fallback restore-keys is missing the newly installed package. The developer removes the restore-keys configuration entirely, ensuring that only an exact lockfile match restores the cache, forcing npm ci to run fresh when dependencies change but guaranteeing correctness.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T00:45:27.633396+00:00— report_created — created