Dynamic metadata fails fetch on SSG Components #53036
Answered
by
hyjoong
nicolasCinzer
asked this question in
Help
-
SummaryHi NextJS Community! 😄 Im strugglin with this error! In my app theres a dynamic route that im trying to generate statics props for some Link components. My problems appears when building is running... If i generate the metadata like this: export async function generateMetadata({ params: { name } }: Props): Promise<Metadata> {
const [exercise]: Exercise[] = await getExercises({ name, queryType: 'equal' })
console.log(exercise)
if (!exercise.id) {
return {
title: 'Exercise not Found'
}
}
return {
title: exercise.name,
description: `This is the page of ${exercise.name}`
}
} The build fails on fetching and generating those pages The builds message:
but if i remove the fetch getExercises() and set the title of the name param like this: export async function generateMetadata({ params: { name } }: Props): Promise<Metadata> {
// const [exercise]: Exercise[] = await getExercises({ name, queryType: 'equal' })
// console.log(exercise)
// if (!exercise.id) {
// return {
// title: 'Exercise not Found'
// }
// }
return {
title: /* exercise. */name,
description: `This is the page of ${/* exercise. */name}`
}
} The build runs like butter! Im missing some point on this? Or theres a problem? Thx community! Additional informationNo response ExampleNo response |
Beta Was this translation helpful? Give feedback.
Answered by
hyjoong
Jul 22, 2023
Replies: 1 comment 4 replies
-
Use the try{} catch{} statement. export async function generateMetadata({ params: { name } }: Props): Promise<Metadata> {
try {
const [exercise]: Exercise[] = await getExercises({
name,
queryType: "equal",
});
return {
title: exercise.name,
description: `This is the page of ${exercise.name}`,
};
} catch (e) {
return {
title: "Exercise not Found",
};
}
} |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
nicolasCinzer
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use the try{} catch{} statement.