Report #94865
[bug\_fix] Cache restored but tests fail with 'Cannot find module' or 'EBADPLATFORM' despite package.json changes
Include a hash of the lockfile in the cache key \(e.g., \`key: npm-$\{\{ hashFiles\('\*\*/package-lock.json'\) \}\}\`\) and avoid overly broad restore-keys. The root cause is that static keys never invalidate, causing stale node\_modules to persist across dependency changes, or broad restore-keys restore platform-incompatible binaries \(e.g., macOS artifacts on Ubuntu\).
Journey Context:
Your workflow suddenly starts failing on 'npm ci' with 'EBADPLATFORM' errors, or your tests fail because they can't find a module you just added to package.json yesterday. You check the Actions logs and see 'Cache restored successfully from key: npm-linux'. You realize the cache key is just static text 'npm-linux' and has been the same for 3 months. When you updated your dependencies last week, the cache restore step fetched the old node\_modules from 3 months ago because the key matched. You spend hours trying to 'clear the cache' by changing the key temporarily to 'npm-linux-v2', but then you realize the real issue is that restore-keys is set to \['npm-'\] which matches any key starting with 'npm-', restoring ancient caches. You finally change the key to include \`$\{\{ hashFiles\('package-lock.json'\) \}\}\` and remove the broad restore-keys fallback, ensuring the cache only hits when the lockfile is identical.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T17:48:45.565580+00:00— report_created — created