[recovery] Disable Next image on-disk cache on read-only Netlify Lambda#18781
[recovery] Disable Next image on-disk cache on read-only Netlify Lambda#18781pettinarip wants to merge 1 commit into
Conversation
✅ Deploy Preview for ethereumorg ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Next 16's image optimizer eagerly initializes a disk LRU cache in its
constructor, calling mkdir('.next/cache/images') at runtime. On Netlify's
read-only Lambda filesystem (/var/task) this mkdir fails with ENOENT, and
because the init promise is created eagerly and not awaited/caught at that
point, it surfaces as an unhandled promise rejection in the
___netlify-server-handler function.
Set images.maximumDiskCacheSize to 0 so the disk cache is never
initialized (isDiskCacheEnabled stays false, getOrInitDiskLRU is never
called). The local disk cache is useless on ephemeral read-only functions
anyway -- optimized images are served via Netlify's image CDN
(NEXT_FORCE_EDGE_IMAGES).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
8bc41ae to
e6ba8cc
Compare
🔎 First-pass review — ✅ Looks mergeableSets Analysis
|
|
Caution Review failedAn error occurred during the review process. Please try again later. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |

Error
Recurring unhandled promise rejection in the
___netlify-server-handlerfunction (11 hits, first seen 2026-05-25):Root cause
Next.js 16's image optimizer (
ImageOptimizerCache,next/dist/server/image-optimizer.js:686-694) eagerly initializes an on-disk LRU cache in its constructor whenever:cacheHandleris set, andimages.maximumDiskCacheSize !== 0, andexperimental.isrFlushToDiskis truthyAll three hold by default in our config. That eager
getOrInitDiskLRU(...)promise (disk-lru-cache.external.js:36) callsfs.promises.mkdir(cacheDir, { recursive: true })wherecacheDir = .next/cache/images. On Netlify's read-only Lambda filesystem (/var/task), creating.next/cachefails withENOENT.Because the promise is created eagerly in the constructor and not awaited or caught at that point (only later inside
get()/set()), the rejection escapes as an unhandled promise rejection and crashes/pollutes the server handler.Fix
Set
images.maximumDiskCacheSize: 0innext.config.js. Per the constructor guard, this leavesisDiskCacheEnabledfalse sogetOrInitDiskLRUis never called — nomkdir, no rejection.maximumDiskCacheSizeis a documented public image option (z.number().int().min(0).optional()in Next's config schema). The local disk image cache is useless on ephemeral, read-only Lambda anyway — optimized images are served through Netlify's image CDN (NEXT_FORCE_EDGE_IMAGES=true), so there is no functional regression.Affected files
next.config.jsVerification
pnpm type-check✅pnpm exec eslint next.config.js✅ (clean)🤖 Generated with Claude Code