I’m building a website with Nextjs (14.2.3) and next-intl (“^3.14.1”), encountering buildtime 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
Some people have encountered the similar problem before: https://github.com/amannn/next-intl/issues/521
So I call unstable_setRequestLocale
function in most of the layout.tsx
and page.tsx
, like the snippet below:
import React from 'react';
import { unstable_setRequestLocale } from 'next-intl/server';
import AboutPage from '@/layout/AboutPage';
interface AboutPageProps {
params: {
locale: string;
};
}
const Page: React.FC<AboutPageProps> = ({ params: { locale } }) => {
unstable_setRequestLocale(locale);
return <AboutPage />;
};
export default Page;
It solved the most of the errors, except I got this last error as like the pictures below and I couldn’t figure out how to solve this…
This is the current directory is like:
├── messages
│ ├── en.json
│ └── ...
├── next.config.mjs
└── src
├── i18n.ts
├── middleware.ts
└── app
├── layout.tsx
├── page.tsx
└── [locale]
├── layout.tsx
└── page.tsx
And this is the code snippet in the /app/layout.tsx
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return children;
}
I guess this is where it goes wrong, I’ve tried to call unstable_setRequestLocale
function here but it would cause more errors. I even tried to downgrade the Next.js version to 14.0.3, but I git the same problem.
I have no idea how to solove this, hoping if anyone has the solution. Many thanks in advance!
1