nextjs - 💡(How to fix) Fix next/image stale cache in development when overwriting files in public/ directory [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#93430Fetched 2026-05-03 04:37:42
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
0
Timeline (top)
labeled ×2closed ×1commented ×1issue_type_added ×1

Fix Action

Fix / Workaround

What DOES work (Workarounds):

Code Example

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Home Single Language
  Available memory (MB): 7522
  Available CPU cores: 12
Binaries:
  Node: 22.21.1
  npm: 11.11.0
  pnpm: 10.33.0
Relevant Packages:
  next: 16.2.4
  react: 19.2.5
  react-dom: 19.2.5
  typescript: 5.9.3
Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

any nextjs project

To Reproduce

  1. Start the application in development: npm run dev
  2. Open a page that displays an image using <Image src="/my-image.png" width={500} height={300} /> (where the file is in the public/ folder).
  3. While the dev server is running, replace the physical file at public/my-image.png with a completely different image file but keep the filename identical.
  4. Hard refresh the browser (Ctrl + F5).
  5. Observe that the old image is still displayed.
  6. Stop and restart the development server—the old image still persists.

Current vs. Expected behavior

Current Behavior: Next.js serves a stale optimized version of the image from the .next/cache/images directory. The internal image optimization cache does not seem to watch for file system changes in the public/ directory when the filename remains the same.

What DOES NOT work to fix it:

  • Normal browser refresh.
  • Hard browser refresh (Ctrl + F5).
  • Restarting the development server (npm run dev).
  • Clearing browser cache/cookies.

What DOES work (Workarounds):

  • Manually deleting the .next folder or the .next/cache/images subfolder.
  • Renaming the file (e.g., image.png -> image-v2.png) and updating the code.

Expected Behavior: Following the steps from the previous section, I expected the new image to be rendered after a file swap in the public/ folder. Next.js should detect the file modification and invalidate the local image cache automatically during development.

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Home Single Language
  Available memory (MB): 7522
  Available CPU cores: 12
Binaries:
  Node: 22.21.1
  npm: 11.11.0
  pnpm: 10.33.0
Relevant Packages:
  next: 16.2.4
  react: 19.2.5
  react-dom: 19.2.5
  typescript: 5.9.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Image (next/image)

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

This issue is consistently reproducible on Windows 11. It breaks the developer experience when iterating on assets like logos or hero banners, as developers expect a file replacement to be reflected in the UI (HMR) but instead find themselves having to manually clear the .next cache directory multiple times a day.

extent analysis

TL;DR

Manually deleting the .next/cache/images subfolder or renaming the image file can resolve the issue of Next.js serving a stale optimized version of an image after it has been replaced in the public/ folder.

Guidance

  • The issue seems to be related to the internal image optimization cache in Next.js not watching for file system changes in the public/ directory when the filename remains the same.
  • To verify if the cache is the cause, try manually deleting the .next/cache/images subfolder and see if the new image is displayed after a hard refresh.
  • As a temporary workaround, renaming the image file (e.g., image.png -> image-v2.png) and updating the code can force Next.js to reload the new image.
  • Consider exploring Next.js configuration options or plugins that might help with automatic cache invalidation during development.

Example

No specific code snippet is provided as the issue seems to be related to the Next.js configuration and caching behavior rather than a specific code error.

Notes

This issue appears to be specific to the development environment (next dev) and might not affect production builds. The provided workarounds can help mitigate the issue, but a more permanent solution might require further investigation into Next.js caching mechanisms or configuration options.

Recommendation

Apply the workaround of manually deleting the .next/cache/images subfolder or renaming the image file, as upgrading to a fixed version is not explicitly implied in the provided information. This approach can help resolve the issue temporarily until a more permanent solution is found.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

nextjs - 💡(How to fix) Fix next/image stale cache in development when overwriting files in public/ directory [1 comments, 2 participants]