Skip to content

[🐛 Bug]: generateStaticParams forces to be on the edge on nested routes. #899

Open
@rickmartensnl

Description

@rickmartensnl

next-on-pages environment related information

System:
        Platform: darwin
        Arch: arm64
        Version: Darwin Kernel Version 24.1.0: Thu Oct 10 22:08:48 PDT 2024; root:xnu-11215.41.3~5/RELEASE_ARM64_T6000
        CPU: (10) arm64 Apple M1 Pro
        Memory: 32 GB
        Shell: /bin/zsh
Package Manager Used: npm (10.8.1)

Relevant Packages:
        @cloudflare/next-on-pages: 1.13.5
        vercel: 37.12.1
        next: 15.0.1

Description

When deploying a Next.js application on Cloudflare Pages with @cloudflare/next-on-pages, dynamic routes using static parameters (e.g., [locale] for language-based URLs) experience unexpected build errors if they contain nested routes. Specifically, routes like /[locale]/page.tsx (e.g., /en, /nl) build and render correctly. However, nested pages such as /[locale]/test/page.tsx (e.g., /en/test, /nl/test) fail to build unless configured to use the Edge Runtime by exporting export const runtime = 'edge';.

This requirement appears to be a misconfiguration in @cloudflare/next-on-pages, as the Edge Runtime should not be mandatory for these routes. This issue does not occur when deploying the same Next.js app structure to Vercel, where dynamic and nested routes function without needing the Edge Runtime, as expected.

Expected Behavior:
Both /[locale]/page.tsx and /[locale]/test/page.tsx routes should build and render without requiring the Edge Runtime. These routes work as expected in a Vercel deployment, with dynamic and nested routes rendering without Edge Runtime configuration. The requirement for the Edge Runtime on Cloudflare Pages is unexpected and blocks deployment for dynamic, multi-language route structures.

Observed Behavior:
The build fails for nested dynamic routes unless the Edge Runtime is explicitly set, which should not be necessary and deviates from typical Next.js behavior on other platforms. This leads to inconsistencies between platforms and prevents successful deployment on Cloudflare Pages for standard Next.js dynamic route setups.

Reproduction

  1. Clone the repository: https://github.com/rickmartensnl/cf-pages-dynamic-edge-issue.
  2. Run the following command to build the project:
    npm run pages:build
  3. Observe the build output. Cloudflare Pages generates a series of warnings and errors indicating that non-static routes must be configured with the Edge Runtime to build correctly.

Pages Deployment Method

None

Pages Deployment ID

No response

Additional Information

> [email protected] pages:build
> npx @cloudflare/next-on-pages

⚡️ @cloudflare/next-on-pages CLI v.1.13.5
⚡️ Detected Package Manager: npm (10.8.1)
⚡️ Preparing project...
⚡️ Project is ready
⚡️ Building project...
▲  Vercel CLI 37.12.1
▲  WARNING: You should not upload the `.next` directory.
▲  Installing dependencies...
▲  up to date in 276ms
▲  33 packages are looking for funding
▲  run `npm fund` for details
▲  Detected Next.js version: 15.0.1
▲  Running "npm run build"
▲  > [email protected] build
▲  > next build
▲  ▲ Next.js 15.0.1
▲  
▲  Creating an optimized production build ...
▲  ⚠ Found lockfile missing swc dependencies, run next locally to automatically patch
▲  ⚠ Found lockfile missing swc dependencies, run next locally to automatically patch
▲  ⚠ Found lockfile missing swc dependencies, run next locally to automatically patch
▲  ✓ Compiled successfully
▲  Linting and checking validity of types ...
▲  Collecting page data ...
▲  ⚠ Found lockfile missing swc dependencies, run next locally to automatically patch
▲  ⚠ Using edge runtime on a page currently disables static generation for that page
▲  Generating static pages (0/8) ...
▲  Generating static pages (2/8)
▲  Generating static pages (4/8) 
▲    Generating static pages (6/8) 
▲  ✓ Generating static pages (8/8)
▲  Finalizing page optimization ...
▲  Collecting build traces ...
▲  
▲  Route (app)                              Size     First Load JS
▲  ┌ ○ /                                    5.64 kB         105 kB
▲  ├ ƒ /_not-found                          149 B          99.3 kB
▲  ├ ● /[locale]                            149 B          99.3 kB
▲  ├   ├ /nl
▲  ├   └ /en
▲  ├ ● /[locale]/test                       149 B          99.3 kB
▲  ├   ├ /nl/test
▲  ├   └ /en/test
▲  └ ƒ /api/hello                           149 B          99.3 kB
▲  + First Load JS shared by all            99.1 kB
▲  ├ chunks/215-a5930070353d5622.js       44.6 kB
▲  ├ chunks/4bd1b696-21eeec6ae99fe726.js  52.6 kB
▲  └ other shared chunks (total)          1.91 kB
▲  ○  (Static)   prerendered as static content
▲  ●  (SSG)      prerendered as static HTML (uses generateStaticParams)
▲  ƒ  (Dynamic)  server-rendered on demand
▲  Traced Next.js server files in: 122.955ms
▲  Created all serverless functions in: 29.208ms
▲  Collected static files (public/, static/, .next/static): 2.345ms
▲  Build Completed in .vercel/output [9s]
⚡️ Completed `npx vercel build`.
⚡️ Invalid prerender config for /[locale]/test
⚡️ Invalid prerender config for /[locale]/test.rsc
⚡️ Invalid prerender config for /[locale]
⚡️ Invalid prerender config for /[locale].rsc

⚡️ ERROR: Failed to produce a Cloudflare Pages build from the project.
⚡️ 
⚡️      The following routes were not configured to run with the Edge Runtime:
⚡️        - /[locale]/test
⚡️ 
⚡️      Please make sure that all your non-static routes export the following edge runtime route segment config:
⚡️        export const runtime = 'edge';
⚡️ 
⚡️      You can read more about the Edge Runtime on the Next.js documentation:
⚡️        https://nextjs.org/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes

Would you like to help?

  • Would you like to help fixing this bug?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions