Skip to content
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

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

Open
1 task done
rickmartensnl opened this issue Oct 26, 2024 · 11 comments · May be fixed by #900
Open
1 task done

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

rickmartensnl opened this issue Oct 26, 2024 · 11 comments · May be fixed by #900
Labels
bug Something isn't working

Comments

@rickmartensnl
Copy link

rickmartensnl commented Oct 26, 2024

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?
@rickmartensnl rickmartensnl added the bug Something isn't working label Oct 26, 2024
@rickmartensnl
Copy link
Author

rickmartensnl commented Oct 26, 2024

After some more testing I found out that when using @cloudflare/[email protected] it also failed for the /[locale] endpoint, which means between 1.12.1 and 1.13.1 there was a fix for this issue, but did not fully fix the issue.

@cloudflare/[email protected]...@cloudflare/[email protected]

@Moon-DaeSeung
Copy link

I have same issue

@dgknca
Copy link

dgknca commented Nov 16, 2024

same here

@jLynx
Copy link

jLynx commented Dec 6, 2024

same

1 similar comment
@mrtnrs
Copy link

mrtnrs commented Dec 8, 2024

same

@hamidzadeh
Copy link

Same :/

@jLynx
Copy link

jLynx commented Dec 8, 2024

I was able to get it working by setting
compatibility_date = "2024-12-05" in my wrangler.toml file

#:schema node_modules/wrangler/config-schema.json
name = "my-test-site"
compatibility_date = "2024-12-05"
compatibility_flags = ["nodejs_compat"]
pages_build_output_dir = ".vercel/output/static"

@N1ark
Copy link

N1ark commented Dec 15, 2024

The above fix didn't work for me.

Issue seems to occur starting from https://github.com/vercel/vercel/releases/tag/[email protected], where I'm getting an issue when building static routes without runtime = 'edge' despite the route being fully static (dynamic = "error", dynamicParams = false).

Error occurs in a path myPath/[[...args]]/ -- might be related?

Could be related to #833 -- for now I stick to https://github.com/vercel/vercel/releases/tag/[email protected].

@hamidzadeh
Copy link

The above fix didn't work for me.

Issue seems to occur starting from https://github.com/vercel/vercel/releases/tag/[email protected], where I'm getting an issue when building static routes without runtime = 'edge' despite the route being fully static (dynamic = "error", dynamicParams = false).

Error occurs in a path myPath/[[...args]]/ -- might be related?

Could be related to #833 -- for now I stick to https://github.com/vercel/vercel/releases/tag/[email protected].

yes, the same worked for me.

@RokasVCheckatrade
Copy link

The above fix didn't work for me.
Issue seems to occur starting from vercel/vercel@[email protected] (release), where I'm getting an issue when building static routes without runtime = 'edge' despite the route being fully static (dynamic = "error", dynamicParams = false).
Error occurs in a path myPath/[[...args]]/ -- might be related?
Could be related to #833 -- for now I stick to vercel/vercel@[email protected] (release).

yes, the same worked for me.

What nexths and next-on-pages version are you using? I've tried downgrading vercel to 34.4.0, but with latest 1.13.7 next-on-pages version I still get an error about edge runtime.

@N1ark
Copy link

N1ark commented Dec 16, 2024

What nexths and next-on-pages version are you using? I've tried downgrading vercel to 34.4.0, but with latest 1.13.7 next-on-pages version I still get an error about edge runtime.

Ah yes -- I forgot to mention, I'm using @cloudflare/[email protected], the issue arises again with 1.13.7 (didn't get to try 1.13.6)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants