I have a problem with Next.JS’s not-found.tsx (using /app)
Here’s the error:
Error: Usage of next-intl APIs in Server Components currently opts into dynamic rendering. This limitation will eventually be lifted, but as a stopgap solution, you can use the `unstable_setRequestLocale` API to enable static rendering, see https://next-intl-docs.vercel.app/docs/getting-started/app-router-server-components#static-rendering
at /vercel/path0/.next/server/chunks/8008.js:20:5350
at /vercel/path0/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:185493
at l (/vercel/path0/.next/server/chunks/8008.js:20:5818)
at /vercel/path0/.next/server/chunks/8008.js:20:4732
at /vercel/path0/.next/server/chunks/8008.js:20:4735
at s (/vercel/path0/.next/server/chunks/8008.js:20:5096)
at w (/vercel/path0/.next/server/chunks/4326.js:1:9329)
at eh (/vercel/path0/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:134786)
at e (/vercel/path0/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:137671)
at ek (/vercel/path0/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:138145)
✓ Generating static pages (5/5)
> Export encountered errors on following paths:
/_not-found/page: /_not-found
It looks like the problem is related to the usage of next-intl in your Server Components, specifically in the not-found.tsx file.
You would need to make a few changes to your not-found.tsx file:
Import the necessary functions from next-intl.
Use the unstable_setRequestLocale function to set the locale.
Wrap your component with the NextIntlClientProvider if you need to use internationalization features within the component.
Code Example
import React from "react"
import Link from "next/link"
import { Button, Card, CardBody, CardFooter } from "@nextui-org/react"
import { unstable_setRequestLocale } from 'next-intl/server'
import { NextIntlClientProvider } from 'next-intl'
import { useLocale } from 'next-intl'
export default function NotFound() {
const locale = useLocale()
unstable_setRequestLocale(locale)
return (
<NextIntlClientProvider locale={locale}>
<div className="flex min-h-screen items-center justify-center">
<Card className="w-full max-w-md rounded-[25px] p-6 shadow-lg">
<CardBody>
<h2 className="mb-2 text-center text-3xl font-extrabold">
Not Found
</h2>
<h3 className="text-center">Could not find requested resource</h3>
</CardBody>
<CardFooter>
<div className="flex justify-center align-middle">
<Link href="/" className="mx-2">
<Button className="bg-[#00699e]">Return Home</Button>
</Link>
<Link href="https://...." className="mx-2">
<Button className="bg-[#fff] text-[#000]">Discord</Button>
</Link>
<Link href="https://...." className="mx-2">
<Button className="bg-[#eb2626]">Twitter / X</Button>
</Link>
</div>
</CardFooter>
</Card>
</div>
</NextIntlClientProvider>
)
}
This modification should resolve the error you’re encountering during production builds on Vercel. The unstable_setRequestLocale function enables static rendering for the page, which is compatible with static exports.
Additionally, make sure that your next.config.js file is properly configured for next-intl. It should look something like this:
Remember that the unstable_ prefix in the function name indicates that this API might change in future versions, so keep an eye on the next-intl documentation for any updates .