Next.js Discord

Discord Forum

Cannot read properties of slug

Unanswered
Arinji posted this in #help-forum
Open in Discord
I am trying to generate an opengraph image, so currently i just pushed a basic nextjs example to test if tailwind works, but on build it fails

My code
import { ImageResponse } from "next/og";

export const runtime = "nodejs";

export const alt = "About Revivenode";
export const size = {
  width: 1200,
  height: 630,
};
export const contentType = "image/png";

export default async function Image({ params }: { params: { slug: string } }) {
  return new ImageResponse(
    <div className="w-full h-full bg-red-500">{params.slug}</div>,
    {
      ...size,
    }
  );
}


Error
Error occurred prerendering page "/opengraph-image". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Cannot read properties of undefined (reading 'slug')


I want to get the url the user is at, like /faq.. so i have the params.slug.. why is it undefined tho

The docs say
params (optional)
An object containing the dynamic route parameters object from the root segment down to the segment opengraph-image or twitter-image is colocated in.

But all my pages are static, will the params object not work here?

0 Replies