Skip to content

Turbopack build fails when optional catch-all layout exports generateStaticParams alongside parallel routes #84509

@luishdz1010

Description

@luishdz1010

Link to the code that reproduces this issue

https://github.com/luishdz1010/next-bug-turbo-parallel-routes

To Reproduce

  1. Clone this reproduction repo:
npx degit luishdz1010/next-bug-turbo-parallel-routes next-bug-turbo-parallel-routes
cd next-bug-turbo-parallel-routes
pnpm install
  1. Run pnpm build.

  2. Observe the failure while collecting page data for /[tenant]/c with the referenced stack trace.

Current vs. Expected behavior

next build fails under Turbopack when a layout for app/[tenant]/[[...pages]] exports generateStaticParams while the same route tree also defines a parallel route slot (@nav/c). During static path generation Turbopack attempts to destructure the param descriptor for pages from the regex associated with /[tenant]/c, but that route does not declare the optional catch-all param, leading to:

TypeError: Cannot destructure property 'repeat' of 'regex.groups[paramName]' as it is undefined.
    at ignore-listed frames

> Build error occurred
Error: Failed to collect page data for /[tenant]/c

Works fine with --webpack, also works fine with Turbo's dev mode.

Expected

next build should succeed with Turbopack. Routes that do not define a pages param should not receive static params generated for sibling branches.

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #202508231538~1757385336~22.04~8f363f2 SMP PREEMPT_DYNAMIC Tue S
  Available memory (MB): 94177
  Available CPU cores: 32
Binaries:
  Node: 24.9.0
  npm: 11.6.0
  Yarn: N/A
  pnpm: 9.15.4
Relevant Packages:
  next: 15.6.0-canary.42 // Latest available version is detected (15.6.0-canary.42).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Turbopack, Parallel & Intercepting Routes

Which stage(s) are affected? (Select all that apply)

next build (local)

Additional context

Using this patch as a workaround:

diff --git a/dist/build/static-paths/app.js b/dist/build/static-paths/app.js
index 1a6b37fa742cc8c47c4b9ae0021d34537bf6c569..de26ca61af03caf08ab5754cda93b8186fc59e62 100644
--- a/dist/build/static-paths/app.js
+++ b/dist/build/static-paths/app.js
@@ -567,6 +567,9 @@ async function buildAppStaticPaths({ dir, page, distDir, cacheComponents, authIn
         } else {
             // Collect all the route param keys that are not parallel route params.
             // These are the ones that will be included in the request pathname.
+            if (!(regex.groups && regex.groups[segment.paramName])) {
+                continue;
+            }
             childrenRouteParamSegments.push({
                 name: segment.name,
                 paramName: segment.paramName,
@@ -637,7 +640,9 @@ async function buildAppStaticPaths({ dir, page, distDir, cacheComponents, authIn
     // Precompile the regex patterns for the route params.
     const paramPatterns = new Map();
     for (const { paramName } of childrenRouteParamSegments){
-        const { repeat, optional } = regex.groups[paramName];
+        const group = regex.groups[paramName];
+        if (!group) continue;
+        const { repeat, optional } = group;
         let pattern = `[${repeat ? '...' : ''}${paramName}]`;
         if (optional) {
             pattern = `[${pattern}]`;

Metadata

Metadata

Assignees

No one assigned

    Labels

    Parallel & Intercepting RoutesRelated to Parallel and/or Intercepting routes.TurbopackRelated to Turbopack with Next.js.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions