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]: Dynamic Pages / Routes can't deploy to Cloudflare Pages #745

Open
1 task done
exepowered opened this issue Apr 17, 2024 · 10 comments
Open
1 task done
Labels
bug Something isn't working

Comments

@exepowered
Copy link

exepowered commented Apr 17, 2024

next-on-pages environment related information

Relevant Packages:
@cloudflare/next-on-pages: 1.11.0
vercel: N/A
next: 14.1.4

Description

I'm currently building a website with Next.js 14 and Prismic.io CMS. It seems like there's an issue with Dynamic Pages / Dynamic Routes on Cloudflare Pages deploy.

When deployed to Vercel or running locally, my app works flawlessly.

On Cloudflare Pages deploy, the pages are marked correctly as λ (Dynamic) server-rendered on demand using Node.js, but the deploy fails:

16:22:18.726	⚡️ ERROR: Failed to produce a Cloudflare Pages build from the project.
16:22:18.726	⚡️ 
16:22:18.726	⚡️ 	The following routes were not configured to run with the Edge Runtime:
16:22:18.726	⚡️ 	  - /[manufacturer]/[uid]
16:22:18.727	⚡️ 	  - /kategoria/[uid]
16:22:18.727	⚡️ 	  - /producent/[uid]
16:22:18.727	⚡️ 
16:22:18.727	⚡️ 	Please make sure that all your non-static routes export the following edge runtime route segment config:
16:22:18.727	⚡️ 	  export const runtime = 'edge';
16:22:18.727	⚡️ 
16:22:18.727	⚡️ 	You can read more about the Edge Runtime on the Next.js documentation:
16:22:18.727	⚡️ 	  https://nextjs.org/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes
16:22:18.727	
16:22:18.747	Failed: Error while executing user command. Exited with error code: 1

When I add export const runtime = 'edge' to my failing page.tsx (although it should work under node.js default runtime, and it does so on Vercel), the page deploys succesfully as ℇ (Edge Runtime) server-rendered on demand using the Edge Runtime.

Now trying to access the page, I'm getting this error:

Application error: a server-side exception has occurred (see the server logs for more information).
Digest: 3018982495
image

Reproduction

Run a Next.js 14 (App Router) app with Dynamic Pages, and Prismic.io CMS in my case. Try deploying to Cloudflare Pages. Example code.:

// src/app/[manufacturer]/[uid]/page.tsx

import { Metadata } from "next";
import { notFound } from "next/navigation";
import { SliceZone } from "@prismicio/react";

import { createClient } from "@/prismicio";
import { components } from "@/slices";

type Params = { uid: string };

export default async function Page({ params }: { params: Params }) {
  const client = createClient();
  const page = await client
    .getByUID("product", params.uid)
    .catch(() => notFound());

  return <SliceZone slices={page.data.slices} components={components} />;
}

export async function generateMetadata({ params }: { params: Params; }): Promise<Metadata> {
  const client = createClient();
  const page = await client
    .getByUID("product", params.uid)
    .catch(() => notFound());

  return {
    title: page.data.meta_title,
    description: page.data.meta_description,
    openGraph: {
      images: [page.data.meta_image?.url || ''],
    },
  };
}

Pages Deployment Method

Pages CI (GitHub/GitLab integration)

Pages Deployment ID

0a8c872 and 114366d

Additional Information

Found a similar issue here, but unable to fix: #32 and #35

Would you like to help?

  • Would you like to help fixing this bug?
@exepowered exepowered added the bug Something isn't working label Apr 17, 2024
@ghost
Copy link

ghost commented May 2, 2024

Facing the same issue here.
image

It seems that the problem is related to importing client components in the page.jsx file.

@diptnc
Copy link

diptnc commented May 11, 2024

same , the dynamic routes with export const runtime = "edge" gives server side error in cloudflare pages

@beyourahi
Copy link

facing the same issue, any solution?

@exepowered
Copy link
Author

exepowered commented Jun 2, 2024

Personally, I switched back to Vercel, at least for now. They support Next.js natively, and apply some nice features e.g. image optimization that Cloudflare Pages doesn't support.

@beyourahi
Copy link

image

Source: https://developers.cloudflare.com/pages/framework-guides/nextjs/deploy-a-nextjs-site/#generatestaticparams

This is straight out of the docs but it doesn't work for me.

@valentinbdv
Copy link

For me, it was working one month ago thanks to dynamicParams = false; and using generateStaticParams but using the same code today gives me this same error: The following routes were not configured to run with the Edge Runtime. It feels like next-on-pages is highly unstable with NextJS and everytime I want to publish my project, I have to fix new issues rising from nowhere.

@valentinbdv
Copy link

After digging, it seems the issue I have is currently being fixed: #833

@Anonymous327
Copy link

image

Source: https://developers.cloudflare.com/pages/framework-guides/nextjs/deploy-a-nextjs-site/#generatestaticparams

This is straight out of the docs but it doesn't work for me.

Hm. Will this ever be compatible with next on pages? You really gotta jump through a lot of hoops to get something similar on CF.

@kazzyfrog
Copy link

facing the same issue, any solution?
I using the latest (1.13.2) version of next-on-pages.

But :(

⚡️ ERROR: Failed to produce a Cloudflare Pages build from the project.
⚡️ 
⚡️      The following routes were not configured to run with the Edge Runtime:
⚡️        - /api/v1/ssg/[slug]
⚡️ 
⚡️      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

@mrtnrs
Copy link

mrtnrs commented Oct 10, 2024

facing the same issue, any solution? I using the latest (1.13.2) version of next-on-pages.

Seen this? Solved my issue.

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

No branches or pull requests

7 participants