Skip to content

Commit 8bc41ae

Browse files
pettinaripclaude
andcommitted
fix: disable Next image on-disk cache on read-only Lambda
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>
1 parent 9e2acee commit 8bc41ae

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

next.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,16 @@ module.exports = (phase) => {
126126
serverExternalPackages: ["pino-pretty", "lokijs", "encoding"],
127127
trailingSlash: true,
128128
images: {
129+
// Disable Next.js's on-disk image cache. Next 16's image optimizer
130+
// eagerly initializes a disk LRU cache that calls
131+
// `mkdir('.next/cache/images')` at runtime. On Netlify's read-only
132+
// Lambda filesystem (`/var/task`) this mkdir fails with ENOENT and, since
133+
// the init promise is created eagerly and never awaited at that point,
134+
// surfaces as an unhandled promise rejection. The local disk cache is
135+
// useless on ephemeral read-only functions anyway -- optimized images are
136+
// served via Netlify's image CDN (NEXT_FORCE_EDGE_IMAGES). Setting this to
137+
// 0 skips disk-cache initialization entirely.
138+
maximumDiskCacheSize: 0,
129139
qualities: [5, 10, 20, 35, 40, 75, 90, 100],
130140
deviceSizes: [640, 750, 828, 1080, 1200, 1504, 1920],
131141
remotePatterns: [

0 commit comments

Comments
 (0)