Next.js Discord

Discord Forum

Dynamic page type error when building on Vercel

Answered
Chum salmon posted this in #help-forum
Open in Discord
Chum salmonOP
Does anybody spot a problem in my code that causes the error in the attached image? I'm using Next.js 15
import { BlogPostData } from "@/data/mockup/MockupData";
import Image from "next/image";
import { notFound } from "next/navigation";

type Params = {
  posts: string;
};

const PostPage = async ({ params }: { params: Params }) => {
  const post = BlogPostData.find(item => item.slug === params.posts);

  if (!post) {
    notFound();
  }

  return (
    <div className="p-md">
      <h1 className="text-2xl font-bold mb-sm">{post.title}</h1>

      <div className="w-full h-[300px] relative mb-md">
        <Image
          src={post.image}
          alt={post.title}
          fill
          priority
          className="object-cover w-full h-full"
        />
      </div>

      <div className="text-base text-primary">
        {post.content}
      </div>
    </div>
  );
};

export default PostPage;
Answered by Yi Lon Ma
- params: Params
+ params: Promise<Params>

- const post = BlogPostData.find(...)
+ const slug = (await params).slug
+ const post = BlogPostData.find(...)
View full answer

3 Replies

Answer
@Yi Lon Ma diff - params: Params + params: Promise<Params> - const post = BlogPostData.find(...) + const slug = (await params).slug + const post = BlogPostData.find(...)
Chum salmonOP
omg works without fail. You're the best!
I think you answered my post before in tailwind dis.
Thanks man!