nextjs - 💡(How to fix) Fix When you have an already existing image in public directory and you add a new file with same name and replace the file, nextjs cant render the new file it will render the old file only with the Image tag [2 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#88489Fetched 2026-04-08 02:04:43
View on GitHub
Comments
2
Participants
2
Timeline
7
Reactions
0
Timeline (top)
commented ×2labeled ×2closed ×1issue_type_added ×1

Code Example

import Image from "next/image";

   export default function Page() {
     return (
       <Image
         src="/hero.png"
         alt="Hero"
         width={500}
         height={300}
       />
     );
   }
3. Start the development server and confirm that the image renders correctly in the browser.

4. Replace the image file in the **`public/`** folder with a different image using the same filename (`hero.png`).
   - Git marks the file as **modified**.

5. Refresh the browser or restart the Next.js development server.

6. Observe that **Next.js still renders the old image**, even though the file in the `public/` folder has been replaced.


### Current vs. Expected behavior

I have uploaded screenshots to illustrate the issue:

1. **Rendered Site:** Shows the website rendering the **old `contact.jpg`**.  
   ![Rendered Site](https://github.com/user-attachments/assets/f2dd0b7c-80a7-48c7-b315-21f209bc232a)

2. **Actual File:** Shows the **updated `contact.jpg`** in the `public/` folder.  
   ![Actual File](https://github.com/user-attachments/assets/17a2f9e3-42d9-4e25-835f-147a28976895)

3. **Code:** Shows the relevant code where the image is rendered using `next/image`.  
   ![Code](https://github.com/user-attachments/assets/14b49600-e188-4449-850f-4b9535e0e948)


### Provide environment information
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/quirky-leftpad-mky7vg?workspaceId=ws_Nh9dmghsN2PEKSFNiM3Mk6

To Reproduce

Steps to Reproduce

  1. Add an image file (for example, hero.png) to the public/ folder of a Next.js project.

  2. Render the image using the Image component from next/image:

    import Image from "next/image";
    
    export default function Page() {
      return (
        <Image
          src="/hero.png"
          alt="Hero"
          width={500}
          height={300}
        />
      );
    }
  3. Start the development server and confirm that the image renders correctly in the browser.

  4. Replace the image file in the public/ folder with a different image using the same filename (hero.png).

    • Git marks the file as modified.
  5. Refresh the browser or restart the Next.js development server.

  6. Observe that Next.js still renders the old image, even though the file in the public/ folder has been replaced.

Current vs. Expected behavior

I have uploaded screenshots to illustrate the issue:

  1. Rendered Site: Shows the website rendering the old contact.jpg.
    Rendered Site

  2. Actual File: Shows the updated contact.jpg in the public/ folder.
    Actual File

  3. Code: Shows the relevant code where the image is rendered using next/image.
    Code

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Home
  Available memory (MB): 15558
  Available CPU cores: 16
Binaries:
  Node: 22.16.0
  npm: 11.4.2
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 16.1.1 // Latest available version is detected (16.1.1).
  eslint-config-next: N/A
  react: 19.2.3
  react-dom: 19.2.3
  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 start (local)

Additional context

I am developing a personal portfolio for now and came across this bug. I haven't deployed it anywhere for now.

extent analysis

TL;DR

The issue can likely be resolved by configuring Next.js to properly handle cache invalidation for images in the public/ folder.

Guidance

  • Verify that the next/image component is being used correctly and that the src attribute is pointing to the correct location of the updated image file.
  • Check the Next.js documentation for cache invalidation strategies, such as using the revalidate option or implementing a custom caching solution.
  • Consider using a library like next-imagopt to optimize and cache images, which may help resolve the issue.
  • Try deleting the .next folder and restarting the development server to ensure that any cached files are removed and rebuilt.

Example

// Example of using the revalidate option with next/image
import Image from "next/image";

export default function Page() {
  return (
    <Image
      src="/hero.png"
      alt="Hero"
      width={500}
      height={300}
      revalidate={60} // Revalidate the image every 60 seconds
    />
  );
}

Notes

The issue may be related to the caching behavior of Next.js, which can cause the old image to be rendered even after the file has been updated. Further investigation into the caching configuration and strategies for cache invalidation may be necessary to fully resolve the issue.

Recommendation

Apply a workaround by configuring cache invalidation for images in the public/ folder, such as using the revalidate option or implementing a custom caching solution, to ensure that updated images are properly rendered in the browser.

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 When you have an already existing image in public directory and you add a new file with same name and replace the file, nextjs cant render the new file it will render the old file only with the Image tag [2 comments, 2 participants]