TX031

Invalid dynamic export

Console

Text.js error TX031: Invalid `dynamic` export … in …. Use "auto", "force-static" or "force-dynamic".

Why this happens

A route handler exports dynamic with a value Text.js does not support. Next.js also accepts "error", which renders the route statically and fails the build if it reads request data. Text.js can't detect request reads, so it rejects "error".

How to fix it

Use "force-static" to cache the handler. A cached handler receives a request with no query string, headers, cookies or body:

app/api/posts/route.tsts
// Beforeexport const dynamic = "error";// Afterexport const dynamic = "force-static";

Use "force-dynamic", or remove the export, if the handler reads the request. See Caching.