Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development environment works, but Route /_not-found couldn't be rendered statically error in production builds. #1407

Closed
3 tasks done
jooy2 opened this issue Oct 9, 2024 · 1 comment
Labels
bug Something isn't working unconfirmed Needs triage.

Comments

@jooy2
Copy link

jooy2 commented Oct 9, 2024

Description

Hello, first of all, I would like to thank you for developing next-intl.

While applying this module to a project that uses Next.js app router, I faced the following problem:

In the development environment, the translation works fine without any errors, but when you do next build for production, the build fails with the following error:

Generating static pages (0/4)  [    ]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/with-i18n-routing#static-rendering
    at /Users/user/nextapp-template/.next/server/chunks/555.js:37:72824
    at /Users/user/nextapp-template/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:185364
    ... 5 lines matching cause stack trace ...
    at /Users/user/nextapp-template/.next/server/chunks/555.js:37:75105
    at /Users/user/nextapp-template/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:185364
    at /Users/user/nextapp-template/.next/server/chunks/555.js:37:75620 {
  digest: '1848317962',
  [cause]: n [Error]: Dynamic server usage: Route /_not-found couldn't be rendered statically because it used `headers`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error
      at c (/Users/user/nextapp-template/.next/server/chunks/555.js:37:126506)
      at d (/Users/user/nextapp-template/.next/server/chunks/555.js:37:79383)
      at /Users/user/nextapp-template/.next/server/chunks/555.js:37:72726
      at /Users/user/nextapp-template/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:185364
      at u (/Users/user/nextapp-template/.next/server/chunks/555.js:37:73566)
      at get locale [as locale] (/Users/user/nextapp-template/.next/server/chunks/555.js:37:74243)
      at /Users/user/nextapp-template/.next/server/app/_not-found/page.js:1:7753
      at /Users/user/nextapp-template/.next/server/chunks/555.js:37:74250
      at /Users/user/nextapp-template/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:185364
      at /Users/user/nextapp-template/.next/server/chunks/555.js:37:75105 {
    description: "Route /_not-found couldn't be rendered statically because it used `headers`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error",
    digest: 'DYNAMIC_SERVER_USAGE'
  }
}
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/with-i18n-routing#static-rendering
    at /Users/user/nextapp-template/.next/server/chunks/555.js:37:72824
    at /Users/user/nextapp-template/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:185364
    ... 5 lines matching cause stack trace ...
    at /Users/user/nextapp-template/.next/server/chunks/555.js:37:75105
    at /Users/user/nextapp-template/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:185364
    at /Users/user/nextapp-template/.next/server/chunks/555.js:37:75620 {
  digest: '1848317962',
  [cause]: n [Error]: Dynamic server usage: Route /_not-found couldn't be rendered statically because it used `headers`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error
      at c (/Users/user/nextapp-template/.next/server/chunks/555.js:37:126506)
      at d (/Users/user/nextapp-template/.next/server/chunks/555.js:37:79383)
      at /Users/user/nextapp-template/.next/server/chunks/555.js:37:72726
      at /Users/user/nextapp-template/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:185364
      at u (/Users/user/nextapp-template/.next/server/chunks/555.js:37:73566)
      at get locale [as locale] (/Users/user/nextapp-template/.next/server/chunks/555.js:37:74243)
      at /Users/user/nextapp-template/.next/server/app/_not-found/page.js:1:7753
      at /Users/user/nextapp-template/.next/server/chunks/555.js:37:74250
      at /Users/user/nextapp-template/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:185364
      at /Users/user/nextapp-template/.next/server/chunks/555.js:37:75105 {
    description: "Route /_not-found couldn't be rendered statically because it used `headers`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error",
    digest: 'DYNAMIC_SERVER_USAGE'
  }
}
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/with-i18n-routing#static-rendering
    at /Users/user/nextapp-template/.next/server/chunks/555.js:37:72824
    at /Users/user/nextapp-template/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:185364
    ... 5 lines matching cause stack trace ...
    at /Users/user/nextapp-template/.next/server/chunks/555.js:37:75105
    at /Users/user/nextapp-template/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:185364
    at /Users/user/nextapp-template/.next/server/chunks/555.js:37:75620 {
  digest: '1848317962',
  [cause]: n [Error]: Dynamic server usage: Route /_not-found couldn't be rendered statically because it used `headers`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error
      at c (/Users/user/nextapp-template/.next/server/chunks/555.js:37:126506)
      at d (/Users/user/nextapp-template/.next/server/chunks/555.js:37:79383)
      at /Users/user/nextapp-template/.next/server/chunks/555.js:37:72726
      at /Users/user/nextapp-template/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:185364
      at u (/Users/user/nextapp-template/.next/server/chunks/555.js:37:73566)
      at get locale [as locale] (/Users/user/nextapp-template/.next/server/chunks/555.js:37:74243)
      at /Users/user/nextapp-template/.next/server/app/_not-found/page.js:1:7753
      at /Users/user/nextapp-template/.next/server/chunks/555.js:37:74250
      at /Users/user/nextapp-template/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:185364
      at /Users/user/nextapp-template/.next/server/chunks/555.js:37:75105 {
    description: "Route /_not-found couldn't be rendered statically because it used `headers`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error",
    digest: 'DYNAMIC_SERVER_USAGE'
  }
}

Error occurred prerendering page "/_not-found". Read more: https://nextjs.org/docs/messages/prerender-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/with-i18n-routing#static-rendering
    at /Users/user/nextapp-template/.next/server/chunks/555.js:37:72824
    at /Users/user/nextapp-template/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:185364
    at u (/Users/user/nextapp-template/.next/server/chunks/555.js:37:73566)
    at get locale [as locale] (/Users/user/nextapp-template/.next/server/chunks/555.js:37:74243)
    at /Users/user/nextapp-template/.next/server/app/_not-found/page.js:1:7753
    at /Users/user/nextapp-template/.next/server/chunks/555.js:37:74250
    at /Users/user/nextapp-template/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:185364
    at /Users/user/nextapp-template/.next/server/chunks/555.js:37:75105
    at /Users/user/nextapp-template/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:185364
    at /Users/user/nextapp-template/.next/server/chunks/555.js:37:75620
 ✓ Generating static pages (4/4)

> Export encountered errors on following paths:
        /_not-found/page: /_not-found

It looks like there is already an issue with the same problem as this one. However, the issue is closed and none of the solutions there worked for me:

#521

There is a reproducible project included in the reproduction course below: (https://github.com/jooy2/nextapp-template)

It's using Next.js 14.2.15, and there are third-party libraries like Material UI and Redux, but I've minimized their use in the project above to a single page.

Could you please check what part of my project is causing the problem, I would like to know if this is due to something I'm doing wrong or if it's a bug in next-intl.

Thank you.

Verifications

  • I've verified that the problem I'm experiencing isn't covered in the docs.
  • I've searched for similar, existing issues on GitHub and Stack Overflow.
  • I've compared my app to a working example to look for differences.

Mandatory reproduction URL

https://github.com/jooy2/nextapp-template

Reproduction description

I am using:

  • Next.js 14.2.15 with App Router
  • Node.js 20.12.0
  • IntelliJ IDEA
  • macOS Sonoma 14.6.1 (M1 Max)

Steps to reproduce:

  1. Clone the following repositories: (https://github.com/jooy2/nextapp-template)
  2. npm i
  3. Perform npm run build.

Expected behaviour

The Next.js build should perform without errors.

@jooy2 jooy2 added bug Something isn't working unconfirmed Needs triage. labels Oct 9, 2024
@jooy2 jooy2 changed the title Development environment works, but "Route /_not-found couldn't be rendered statically" error in production builds. Development environment works, but Route /_not-found couldn't be rendered statically error in production builds. Oct 9, 2024
@amannn
Copy link
Owner

amannn commented Oct 9, 2024

Please have a look at the App Router example, this example has a 404 page that can be statically rendered.

As a side note, at a first glance your layout at app/layout.tsx looks fishy to me. It tries to read a locale param, but is located outside of the [locale] folder. If you compare your implementation with the example, I'm sure you can find differences like this.

I'll move this to a discussion since this is a usage question.

Repository owner locked and limited conversation to collaborators Oct 9, 2024
@amannn amannn converted this issue into discussion #1408 Oct 9, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
bug Something isn't working unconfirmed Needs triage.
Projects
None yet
Development

No branches or pull requests

2 participants