How to Fix Next.js Public Image Path Errors and 404s

At a glance
For public/Images/blog/cover.jpg, request /Images/blog/cover.jpg directly on the deployed domain. It should return the image, not a login page or HTML error. Then open the article that uses the same path.
A common Next.js issue is an image that exists in the project folder but returns a 404 in the browser. The cause is often a path that includes public in the URL, a filename capitalization mismatch, or a file that was not included in the deployed project.
This guide covers the standard public folder convention, examples using next/image, and a simple process for finding the real cause.
Use a two-request test to isolate the failure
For public/Images/blog/cover.jpg, request /Images/blog/cover.jpg directly on the deployed domain. It should return the image, not a login page or HTML error. Then open the article that uses the same path.
If the direct request fails, inspect the committed filename, exact letter case, extension and deployment contents. Windows may hide a case mismatch that appears on a Linux host. If the direct image works but next/image fails, inspect the generated image request and any optimisation error separately.
Do not prepend /public to the browser URL. If the deployment uses a base path, verify the URL under that configuration rather than copying an unrelated example. Finally, test after a clean deployment: an image left over in a local working directory can conceal a missing tracked asset.
Reference: Next.js public-folder documentation.
1. Understand how the public folder works
Next.js serves files placed in the root-level public directory from the site root. The word public is not part of the URL.
For example, if the project contains:
my-next-app/
public/
Images/
blog/
cover.jpg
app/
page.tsx
The public URL path is:
/Images/blog/cover.jpg
It is not /public/Images/blog/cover.jpg.
Official reference: https://nextjs.org/docs/app/api-reference/file-conventions/public-folder
2. Use the correct path with next/image
For a local image in the public folder, the src begins at the root:
import Image from "next/image";
export default function ArticleCover() {
return (
<Image
src="/Images/blog/cover.jpg"
alt="A visual cover for the article"
width={1200}
height={630}
priority
/>
);
}
Use meaningful alternative text that describes the image's purpose. The example sets priority because a hero image may be important to the initial viewport; do not add it to every image on a page. For ordinary below-the-fold images, let the image loading strategy suit the layout and performance needs.
If you use a normal HTML <img> element, the public path convention is the same. The next/image component adds image optimization capabilities, but it cannot correct a URL that points to the wrong location.
3. Check capitalization and filename extensions
File paths may behave differently between local Windows development and a case-sensitive production environment. These are not necessarily equivalent:
/Images/blog/cover.jpg
/images/blog/cover.jpg
/Images/Blog/cover.jpg
/Images/blog/cover.png
Compare the URL character-by-character with the deployed filename. Check whether the actual file is .jpg, .jpeg, .png, or .webp. A renamed image that was not committed or included in the deployment can also produce a 404.
4. Test the exact URL directly
Open the image URL in the browser, not just the page that uses it. For example:
https://www.example.com/Images/blog/cover.jpg
If the direct URL fails, investigate the path or deployment before debugging the React component. If it opens directly but not on the page, inspect the rendered element and the browser Network panel for the request URL and response status.
A practical checklist:
- Confirm the image exists inside the project's root
publicfolder. - Remove
/publicfrom the URL path. - Check filename capitalization and extension.
- Open the exact production URL directly.
- Inspect the Network panel for 404s, redirects, or blocked requests.
- Confirm the file is committed and present in the deployed build.
- Run a production build and test the deployed site.
5. Check base paths and deployment structure
If your site is hosted under a URL prefix instead of the domain root, or uses a Next.js basePath, asset URLs may need additional consideration. Review the deployment configuration and the current Next.js documentation for your setup. Do not add a prefix blindly: first confirm the exact URL where the application is served.
Similarly, if images come from a remote host rather than public, follow the remote image configuration requirements for next/image and verify that the external URL is reachable.
6. Why an image may work locally but fail in production
Common causes include:
- The file exists on your computer but was never committed to Git.
- The filename case differs between the code and the deployed file.
- The URL contains
/public/, which is not part of the public URL. - The image extension in metadata or Markdown does not match the actual file.
- The site uses a path prefix or a deployment-specific domain.
- A remote image host blocks requests or returns an expired URL.
If the image is used in a Markdown blog, check both the frontmatter path and the actual image filename. For example, image: "/Images/blog/cover.jpg" must match a real file at public/Images/blog/cover.jpg.
Frequently asked questions
Do I write public in the image URL?
No. Files in the root public directory are served from the site root, so public/Images/blog/cover.jpg is referenced as /Images/blog/cover.jpg.
Does next/image require width and height?
For a static local image, providing dimensions is a straightforward way to establish its aspect ratio. Other supported layout patterns exist, so follow the component API for the design you're using.
Why does an image work on localhost but return 404 after deployment?
Check whether the image was committed, whether the case and extension match exactly, and whether the deployed URL includes a path prefix. Open the production image URL directly to narrow down the issue.
Research and references
- Next.js public folder convention — https://nextjs.org/docs/app/api-reference/file-conventions/public-folder
- Next.js Image component — https://nextjs.org/docs/app/api-reference/components/image
- Next.js Metadata and OG Images — https://nextjs.org/docs/app/getting-started/metadata-and-og-images
If the source image opens directly but the /_next/image request returns 400, follow the image optimiser 400 diagnostic to check request rules and quality settings.
Try our QR Code Generator
Create clean, scannable QR codes for testing websites, URLs, and client handoffs.

Ukasha Altaf
Software Developer & Digital Tools Creator
Founder of Ukasha Mart. Building free, accessible browser-based utilities and writing in-depth tutorials on modern technology, freelancing, and practical online work.
Explore Further