How to fix Next.js error: getStaticPaths was added without a getStaticProps
Variants
- Without getStaticProps, getStaticPaths does nothing
Solution
Add this empty
getStaticProps
function to your page:export async function getStaticProps {
return { props: {} };
};
More info
Static site generation (SSG) in Next.js uses getStaticPaths
to list out the possible dynamic paths that get mapped to a specific page. After defining your paths with getStaticPaths
, you'll need to include another function called getStaticProps
. This function has a very similar name but serves a different purpose - any values returned from this function will be given as props to your page's component. If you don't have any special props, just define the function and return an empty object. It's unclear why Next.js doesn't handle this case for you, but it's an easy fix nonetheless.