[NEXT-979] i18n config breaks dynamic segments export with generateStaticParams (paths don't match)
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 142k
- Forks
- 32.4k
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 351
Description
Verify canary release
- I verified that the issue exists in the latest Next.js 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
- Create a page in
app/directory with language routing and dynamic segment, e.g.app/[lang]/blog/[slug]/page.tsx - Add
generateStaticParamswith sample slugs and specifiec locale (e.g.'en') - Add basic i18n config to
next.config.js, defaultLocale and locales is enough. defaultLocale should have the same value as used ingenerateStaticParams - Run
next buildand 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure with app/[lang]/blog/[slug]/page.tsx, generateStaticParams, and the locale settings in next.config.js. Start by running next build using the linked reproduction and compare the generated path with the dynamic route pattern; done means the production build succeeds and all app pages using generateStaticParams are prerendered without removing i18n configuration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, next.js, react
- Domain
- build-system, internationalization, web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100