next-intl: 'Error: Usage of next-intl APIs in Server Components is currently only available for dynamic rendering' after upgrading to next@13.5.2

Description

I was previously running on next 13.4.19 using App folder, with my project running without issues. After upgrading to next latest 13.5.2, I started getting the following errors:

Error occurred prerendering page "/_not-found". Read more: https://nextjs.org/docs/messages/prerender-error
Error: Usage of next-intl APIs in Server Components is currently only available for dynamic rendering (i.e. no `generateStaticParams`).

Support for static rendering is under consideration, please refer to the roadmap: https://next-intl-docs.vercel.app/docs/getting-started/app-router-server-components#roadmap

Someone had a similar issue on nextjs without next-intl.

I tried to apply the same solution which was to include to the next.config:

experimental: { serverComponentsExternalPackages: ['next-intl'], },

However, now there is a different error preventing the build to: Error occurred prerendering page "/_not-found". Read more: https://nextjs.org/docs/messages/prerender-error TypeError: Cannot read properties of null (reading 'useContext')

Really tricky bug to trace actually, since we have no further information about it.

Mandatory reproduction URL (CodeSandbox or GitHub repository)

https://codesandbox.io/p/sandbox/next-intl-bug-template-app-forked-6zy5mm

Reproduction description

Steps to reproduce:

  1. Open reproduction
  2. Click on run build
  3. See error: Error: Usage of next-intl APIs in Server Components is currently only available for dynamic rendering (i.e. no generateStaticParams).

Expected behaviour

The app to generate build

About this issue

  • Original URL
  • State: closed
  • Created 9 months ago
  • Reactions: 5
  • Comments: 16 (4 by maintainers)

Most upvoted comments

In my case, setting export const dynamic = 'force-dynamic' only in not-found.tsx files, resolves the error.

This issue is back with next@14.0.4 When I downgrade to next@14.0.3 it works

@onarbf Oh, that’s true! I think it should work.

What I noticed in your app is that you use generateStaticParams. This requires the static rendering integration from next-intl.

Thanks a lot @amannn , it was that. I removed it (I actually don’t need it, it was legacy code from the next-intl previous version) and works fine. Thanks! Great tool 😃

I had the same problem with

Error occurred prerendering page "/_not-found". Read more: https://nextjs.org/docs/messages/prerender-error
Error: Usage of next-intl APIs in Server Components is currently only available for dynamic rendering (i.e. no `generateStaticParams`).

Support for static rendering is under consideration, please refer to the roadmap: https://next-intl-docs.vercel.app/docs/getting-started/app-router-server-components#roadmap.

what I did was usgin this value at the top of my pages components export const dynamic = 'force-dynamic' to create dynamic routes instead of static routes. The information about behavior of the pages is found in here. https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamic