vercel / next.js

The React Framework
https://nextjs.org
MIT License
127.55k stars 27.05k forks source link

[NEXT-979] i18n config breaks dynamic segments export with generateStaticParams (paths don't match) #46622

Open dmgawel opened 1 year ago

dmgawel commented 1 year ago

Verify canary release

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #22 SMP Tue Jan 10 18:39:00 UTC 2023
Binaries:
  Node: 16.17.0
  npm: 8.15.0
  Yarn: 1.22.19
  pnpm: 7.1.0
Relevant packages:
  next: 13.2.3
  eslint-config-next: 13.2.1
  react: 18.2.0
  react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

App directory (appDir: true), Internationalization (i18n)

Link to the code that reproduces this issue

https://codesandbox.io/p/sandbox/next-13-2-i18n-static-params-error-3swobx

To Reproduce

  1. Create a page in app/ directory with language routing and dynamic segment, e.g. app/[lang]/blog/[slug]/page.tsx
  2. Add generateStaticParams with sample slugs and specifiec locale (e.g. 'en')
  3. Add basic i18n config to next.config.js, defaultLocale and locales is enough. defaultLocale should have the same value as used in generateStaticParams
  4. Run next build and observe error:
Error occurred prerendering page "/en/blog/test-1". Read more: https://nextjs.org/docs/messages/prerender-error
Error: The provided export path '/blog/test-1' doesn't match the '/[lang]/blog/[slug]/page' page.
Read more: https://nextjs.org/docs/messages/export-path-mismatch
    at /project/home/dmgawel/workspace/node_modules/next/dist/export/worker.js:99:27
    at Span.traceAsyncFn (/project/home/dmgawel/workspace/node_modules/next/dist/trace/trace.js:79:26)
    at Object.exportPage (/project/home/dmgawel/workspace/node_modules/next/dist/export/worker.js:43:27)
    at execFunction (/project/home/dmgawel/workspace/node_modules/next/dist/compiled/jest-worker/processChild.js:1:2828)
    at execHelper (/project/home/dmgawel/workspace/node_modules/next/dist/compiled/jest-worker/processChild.js:1:2486)
    at execMethod (/project/home/dmgawel/workspace/node_modules/next/dist/compiled/jest-worker/processChild.js:1:2574)
    at process.messageListener (/project/home/dmgawel/workspace/node_modules/next/dist/compiled/jest-worker/processChild.js:1:1284)
    at process.emit (node:events:513:28)
    at emit (node:internal/child_process:939:14)
    at processTicksAndRejections (node:internal/process/task_queues:84:21)

Describe the Bug

Having locales and defaultLocale specified in config file breaks generateStaticParams functionality when running production build. It seems like the default locale is stripped from page path, causing the export path not match the pattern.

Expected Behavior

Build should run smoothly (without removing i18n config from config file, wchich may be needed for pages/ directory), all app/ pages with generateStaticParams should be prerendered.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

NEXT-979

ruucm commented 1 year ago

Yes I has the same issue. This PR is quite promising to fix this.

bhavesh-chaudhari commented 10 months ago

Is this issue fixed? I am getting this error in next@14.0.4

Error occurred prerendering page "/de/feature/chatgpt-for-twitter". Read more: https://nextjs.org/docs/messages/prerender-error -- Error: The provided export path '/feature/chatgpt-for-twitter' doesn't match the '/[lang]/feature/[feature]' page.

This occured after adding i18n property to next.config.js like this:

...
i18n: {
        locales: allLocales,
        defaultLocale: "en",
    },
...

I was trying to fix my rewrites as stated here: https://nextjs.org/docs/app/api-reference/next-config-js/rewrites#rewrites-with-i18n-support

beshur commented 1 month ago

I'm getting this in next15. Any workarounds?