Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

A local image in a Next.js project returns 404 or will not render

ErrorGET /public/images/logo.png 404 (Not Found)

Short answer

Files in public are served from the site root, so public/avatars/me.png is /avatars/me.png. Never write public in the URL. With next/image, set both width and height unless you import the file or use fill. Images from another domain also need a remotePatterns entry.

  • Applies to Next.js 15, Next.js 16, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Open the image URL straight in the browser or with curl. A 404 means the path is wrong; a 200 means the problem is in how the component uses it.

    curl -I http://localhost:3000/images/logo.png
  2. 2Match what you see, then jump to its fix

    1. 1The network tab shows a 404 for a URL that starts with /public/.The path includes the public folder nameFix
    2. 2The page shows an empty box where the image should be, and the Image has no width, height or fill.next/image has no size and the image is not importedFix
    3. 3The component is given a full https URL and the optimiser rejects it with a 400, or the unconfigured host error.The image comes from another domain that is not allowedFix

What does the error look like?

  • GET /public/images/logo.png 404 (Not Found)
  • The image area is blank or collapsed on the page
  • next/image rejects a full URL because its hostname is not configured

Cause 1 of 3

The path includes the public folder name

1Check

Next.js serves the files of public starting from the base URL, so the folder name is not part of the address.

ls public/images/
grep -rn "/public/" app/ components/

2Fix

Drop public from the path and start it with a slash. A file at public/images/logo.png is requested as /images/logo.png.

import Image from 'next/image'

export default function Logo() {
  return <Image src="/images/logo.png" alt="Logo" width={120} height={40} />
}

3Verify

The direct URL returns 200.

curl -I http://localhost:3000/images/logo.png

Confirmed by nextjs.org

Did this fix it?

Cause 2 of 3

next/image has no size and the image is not imported

1Check

next/image needs width and height to reserve space, unless the image is statically imported or the fill property is set.

grep -rn "<Image" app/ components/

2Fix

Give the real pixel size, import the file, or use fill inside a positioned parent.

import Image from 'next/image'
import profile from './profile.png'

// static import: size is read from the file
<Image src={profile} alt="Profile" />

// fill: the parent must be position: relative
<div style={{ position: 'relative', height: 300 }}>
  <Image src="/profile.png" alt="Profile" fill />
</div>

3Verify

Reload and check that the image takes up the space.

npm run dev

Confirmed by nextjs.org

Did this fix it?

Cause 3 of 3

The image comes from another domain that is not allowed

1Check

Each part of the src (protocol, hostname, port, path) is matched exactly against images.remotePatterns. A www or subdomain, or a path that is too narrow, will fail.

grep -n "remotePatterns" -A8 next.config.*

2Fix

Add the exact host and a path pattern to next.config.

// next.config.js
module.exports = {
  images: {
    remotePatterns: [
      {
        protocol: 'https',
        hostname: 'assets.example.com',
        port: '',
        pathname: '/account123/**',
      },
    ],
  },
}

3Verify

Restart the dev server and reload the page.

npm run dev

Confirmed by nextjs.org

Did this fix it?

How do I stop it coming back?

  • Write every public asset path from the root, starting with a slash, and never include the folder name.
  • Import images that live next to the component, so a wrong path fails at build time.
  • Keep one remotePatterns list and add the real subdomain each time a new image host is used.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.