Page exports an invalid "generateMetadata" field
Unanswered
Valentinh posted this in #help-forum
![Avatar](https://cdn.discordapp.com/avatars/309070057017966592/e7b960e313d94771c7aa938008db09b1.webp?size=256)
ValentinhOP
Hi,
When I trying to deploy my app in production on Vercel, I have this error:
My component:
What is the problem please?
When I trying to deploy my app in production on Vercel, I have this error:
Failed to compile.
Type error: Page "app/blog/[slug]/page.tsx" exports an invalid "generateMetadata" field. Page should only export a default React component and configuration options. Learn more: https://nextjs.org/docs/messages/invalid-segment-export
ELIFECYCLE  Command failed with exit code 1.
Error: Command "pnpm run build" exited with 1
My component:
import SingleBlog from "@/components/Blog/SingleBlog";
import Breadcrumb from "@/components/Common/Breadcrumb";
import Pagination from "@/components/Pagination";
import { getClient } from "@/lib/apollo-client";
import { PostDto } from "@/types/generated/graphql";
import { gql } from "@apollo/client";
const GET_PUBLISHED_POSTS_AND_BLOG_PAGE = gql`
query GetPublishedPosts($pagination: PaginationInput!) {
getPublishedPosts(pagination: $pagination) {
posts {
id
title
introduction
postCategory {
name
}
content
slug
publishedAt
image
}
totalCount
totalPages
}
getBlogPage {
id
title
description
}
}
`;
const GET_METADATA = gql`
query GetMeta {
getBlogPage {
id
metaTitle
metaDescription
}
}
`;
export async function generateMetadata() {
const { data } = await getClient().query({
query: GET_METADATA,
});
const { metaTitle, metaDescription } = data.getBlogPage;
return {
title: metaTitle || "Blog",
description: metaDescription || "Découvrez nos dernières actualités.",
};
}
const Blog = async () => {
const { data } = await getClient().query({
query: GET_PUBLISHED_POSTS_AND_BLOG_PAGE,
variables: {
pagination: {
skip: 0,
take: 12,
},
},
});
return (
<></>
);
};
export default Blog;
What is the problem please?
1 Reply
![Avatar](https://cdn.discordapp.com/avatars/678259999201427466/1936f7e8963ff0f800f5eb4b43bc833c.webp?size=256)
Clown
That generateMetadata function definition doesnt look correct to me:
https://nextjs.org/docs/app/building-your-application/optimizing/metadata#dynamic-metadata
https://nextjs.org/docs/app/building-your-application/optimizing/metadata#dynamic-metadata