Next.js build fails with an error starting with “Dynamic server usage”

This error occurs due to a problem with Next.js, where the build process thinks that your route is a static route.


To solve the problem, simply add the below line to your Route Handler, to force dynamic routing.

export const revalidate = 0;