Maaz Zindani

Loading the index…

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

The Open Graph image of a Next.js page does not appear when shared

Errorog:image is missing from the page source

Short answer

Check the rendered HTML first: view the page source and search for og:image. If the tag is missing or wrong, the cause is almost always in the metadata setup: a relative image path without metadataBase, metadata exported from a Client Component, an openGraph object that replaces the parent's, or a file-based image that wins.

  • 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

    Ask the running site what it actually sends. Fetch the HTML and list the Open Graph tags. Share-preview tools read exactly this output.

    curl -s https://example.com/blog/my-post | grep -o '<meta property="og:[^>]*>'
  2. 2Match what you see, then jump to its fix

    1. 1The og:image tag is missing, or the build fails when the image is given as a relative path.A relative image path and no metadataBaseFix
    2. 2Metadata you exported has no effect, and the file starts with 'use client'.The metadata is exported from a Client ComponentFix
    3. 3The home page shows the image, but inner pages lose og:image or og:description.A child page's openGraph replaces the parent's whole objectFix
    4. 4The preview shows an image you did not list in the metadata object.A file-based image is overriding your configFix

What does the error look like?

  • og:image is missing from the page source
  • Link preview shows no image or the wrong image
  • Build error when an openGraph image uses a relative path and no metadataBase is set

Cause 1 of 4

A relative image path and no metadataBase

1Check

Look at how the image is written in the metadata object. Next.js documents that a relative path in a URL-based metadata field without a metadataBase causes a build error.

grep -rn "metadataBase\|openGraph" app/ | head

2Fix

Set metadataBase once in the root layout. Relative image paths are then joined to it and turned into a full URL.

// app/layout.tsx
export const metadata = {
  metadataBase: new URL('https://example.com'),
  openGraph: { images: '/og-image.png' },
}

3Verify

The tag now holds a full https URL.

curl -s https://example.com/ | grep -o '<meta property="og:image"[^>]*>'

Confirmed by nextjs.org

Did this fix it?

Cause 2 of 4

The metadata is exported from a Client Component

1Check

The metadata object and generateMetadata only work in Server Components. Open the page or layout file and look at its first line.

head -n 3 app/blog/[slug]/page.tsx

2Fix

Keep page.tsx a Server Component that exports the metadata, and move the interactive part into a separate file that carries 'use client'.

// app/page.tsx (no 'use client')
import { InteractiveComponent } from './interactive-component'

export const metadata = { title: 'My Page' }

export default function Page() {
  return <InteractiveComponent />
}

3Verify

Rebuild and read the tags again.

npm run build && npm run start
curl -s http://localhost:3000/ | grep -o '<meta property="og:[^>]*>'

Confirmed by nextjs.org

Did this fix it?

Cause 3 of 4

A child page's openGraph replaces the parent's whole object

1Check

Metadata from layouts and pages is merged shallowly, so an openGraph object in a page replaces the openGraph object of the layout instead of adding to it.

grep -rn "openGraph" app/ --include=page.tsx --include=layout.tsx

2Fix

Put the shared image in a variable and spread it into every openGraph object that you override.

// app/shared-metadata.ts
export const openGraphImage = { images: ['https://example.com/og-image.png'] }

// app/about/page.tsx
import { openGraphImage } from '../shared-metadata'
export const metadata = {
  openGraph: { ...openGraphImage, title: 'About' },
}

3Verify

Check an inner page, not only the home page.

curl -s https://example.com/about | grep -o '<meta property="og:[^>]*>'

Confirmed by nextjs.org

Did this fix it?

Cause 4 of 4

A file-based image is overriding your config

1Check

File-based metadata has the higher priority and overrides the metadata object and generateMetadata. Look for an opengraph-image file in the route folders.

find app -name 'opengraph-image*'

2Fix

Keep one source of truth: either delete the file you do not want, or update the file and drop the openGraph.images entry.

rm app/blog/opengraph-image.png

3Verify

Read the og:image tag of that route again.

curl -s https://example.com/blog | grep -o '<meta property="og:image"[^>]*>'

Confirmed by nextjs.org

Did this fix it?

How do I stop it coming back?

  • Set metadataBase in the root layout of every site, so relative image paths always resolve.
  • Keep page.tsx and layout.tsx as Server Components and move interactivity into child files.
  • Share the image through one exported variable instead of writing openGraph in many places.
  • After each change, read the HTML your server sends before blaming the sharing platform.

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.