The Open Graph image of a Next.js page does not appear when shared
og:image is missing from the page sourceShort 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.
Fix it fast
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:[^>]*>'2Match what you see, then jump to its fix
- 1
The 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
Metadata you exported has no effect, and the file starts with 'use client'.The metadata is exported from a Client ComponentFix - 3
The 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
The preview shows an image you did not list in the metadata object.A file-based image is overriding your configFix
- 1
What does the error look like?
og:image is missing from the page sourceLink preview shows no image or the wrong imageBuild 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/ | head2Fix
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
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.tsx2Fix
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
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.tsx2Fix
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
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.png3Verify
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
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
Web apps
Apollo Server rejects a request as a potential CSRF
HTTP 400 Bad Request from the GraphQL endpoint
Apollo Server's CSRF prevention is on by default.
3 causes, each with a fixWeb apps
Clerk cannot read its publishable key in a Next.js app
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY is undefined
Clerk reads NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY.
3 causes, each with a fixWeb apps
The shell cannot find create-next-app
command not found: create-next-app
create-next-app is not meant to be installed as a shell command.
2 causes, each with a fixWeb apps
ESLint fails with: Cannot find module 'next/babel'
ESLint stops on the first file with a Babel or parser error instead of listing lint results
next/babel is a Babel preset that ships inside the next package.
3 causes, each with a fixWeb apps
Firebase Auth says the API key is not valid
Firebase: Error (auth/api-key-not-valid.-please-pass-a-valid-api-key.)
The apiKey your app sends is either empty, wrong, or blocked.
4 causes, each with a fixWeb apps
Jest fails with SyntaxError: Unexpected token when testing a Next.js component
Jest failed to parse a file.
Jest only understands plain JavaScript until a transform and a few file mappings tell it more.
3 causes, each with a fix