Next.js "missing exported function getStaticPaths" - Fix in CI
A dynamic Pages Router route ([id].tsx) that exports getStaticProps must also export getStaticPaths so Next knows which paths to pre-render. Missing it fails the build.
What this error means
The build fails with Error: getStaticPaths is required for dynamic SSG pages and is missing for <route>.
Error: getStaticPaths is required for dynamic SSG pages and is missing
for '/product/[id]'.
Read more: https://nextjs.org/docs/messages/invalid-getstaticpaths-valueCommon causes
getStaticProps without getStaticPaths
The dynamic route opts into static generation via getStaticProps but never declares which params to build.
Wrong rendering choice
The page should be server-rendered or use fallback rendering instead of full SSG.
How to fix it
Add getStaticPaths
- Export getStaticPaths returning the params to pre-render and a fallback mode.
export async function getStaticPaths() {
return { paths: [{ params: { id: '1' } }], fallback: 'blocking' };
}Switch to server rendering
- If paths are not known at build time, use getServerSideProps instead.
export async function getServerSideProps(ctx) {
return { props: { id: ctx.params.id } };
}How to prevent it
- Pair getStaticProps with getStaticPaths on every dynamic SSG route.
- Pick a rendering strategy explicitly per route.