next-on-pages icon indicating copy to clipboard operation
next-on-pages copied to clipboard

[🐛 Bug]: Pages that could be static is being forced to run in the edge

Open Chenalejandro opened this issue 1 year ago • 1 comments

next-on-pages environment related information

[email protected] deploy npm run pages:build && wrangler pages deploy

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

⚡️ @cloudflare/next-on-pages CLI v.1.11.0 ⚡️ Detected Package Manager: npm (10.5.0) ⚡️ Preparing project... ⚡️ Project is ready ⚡️ Building project... ▲ Vercel CLI 34.1.1 ▲ WARNING: You should not upload the .next directory. ▲ Installing dependencies... ▲ up to date in 746ms ▲ 164 packages are looking for funding ▲ run npm fund for details ▲ Detected Next.js version: 14.2.2 ▲ Detected package-lock.json generated by npm 7+ ▲ Running "npm run build" ▲ > [email protected] build ▲ > next build ▲ ▲ Next.js 14.2.2 ▲ - Environments: .env ▲ Creating an optimized production build ... ▲ ✓ Compiled successfully ▲ Linting and checking validity of types ... ▲ Collecting page data ... ▲ ⚠ Using edge runtime on a page currently disables static generation for that page ▲ Generating static pages (0/4) ... ▲ Generating static pages (1/4) ▲ Generating static pages (2/4) ▲ TypeError: Cannot read properties of undefined (reading 'prepare') ▲ at tO.prepareQuery (/home/alejandro/myproject/.next/server/app/page.js:13:17804) ▲ at tO.prepareOneTimeQuery (/home/alejandro/myproject/.next/server/app/page.js:13:16716) ▲ at tn._prepare (/home/alejandro/myproject/.next/server/app/page.js:13:5354) ▲ at tn.all (/home/alejandro/myproject/.next/server/app/page.js:13:5539) ▲ at tn.execute (/home/alejandro/myproject/.next/server/app/page.js:13:5651) ▲ at tn.then (/home/alejandro/myproject/.next/server/app/page.js:13:661) { ▲ digest: '704320559' ▲ } ▲ TypeError: Cannot read properties of undefined (reading 'prepare') ▲ at tO.prepareQuery (/home/alejandro/myproject/.next/server/app/page.js:13:17804) ▲ at tO.prepareOneTimeQuery (/home/alejandro/myproject/.next/server/app/page.js:13:16716) ▲ at tn._prepare (/home/alejandro/myproject/.next/server/app/page.js:13:5354) ▲ at tn.all (/home/alejandro/myproject/.next/server/app/page.js:13:5539) ▲ at tn.execute (/home/alejandro/myproject/.next/server/app/page.js:13:5651) ▲ at tn.then (/home/alejandro/myproject/.next/server/app/page.js:13:661) ▲ at runNextTicks (node:internal/process/task_queues:60:5) ▲ at listOnTimeout (node:internal/timers:540:9) ▲ at process.processTimers (node:internal/timers:514:7) { ▲ digest: '2579839777' ▲ } ▲ TypeError: Cannot read properties of undefined (reading 'prepare') ▲ at tO.prepareQuery (/home/alejandro/myproject/.next/server/app/page.js:13:17804) ▲ at tO.prepareOneTimeQuery (/home/alejandro/myproject/.next/server/app/page.js:13:16716) ▲ at tn._prepare (/home/alejandro/myproject/.next/server/app/page.js:13:5354) ▲ at tn.all (/home/alejandro/myproject/.next/server/app/page.js:13:5539) ▲ at tn.execute (/home/alejandro/myproject/.next/server/app/page.js:13:5651) ▲ at tn.then (/home/alejandro/myproject/.next/server/app/page.js:13:661) ▲ at runNextTicks (node:internal/process/task_queues:60:5) ▲ at listOnTimeout (node:internal/timers:540:9) ▲ at process.processTimers (node:internal/timers:514:7) { ▲ digest: '2579839777' ▲ } ▲ Generating static pages (3/4) ▲ Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error ▲ ▲ TypeError: Cannot read properties of undefined (reading 'prepare') ▲ at tO.prepareQuery (/home/alejandro/myproject/.next/server/app/page.js:13:17804) ▲ at tO.prepareOneTimeQuery (/home/alejandro/myproject/.next/server/app/page.js:13:16716) ▲ at tn._prepare (/home/alejandro/myproject/.next/server/app/page.js:13:5354) ▲ at tn.all (/home/alejandro/myproject/.next/server/app/page.js:13:5539) ▲ at tn.execute (/home/alejandro/myproject/.next/server/app/page.js:13:5651) ▲ at tn.then (/home/alejandro/myproject/.next/server/app/page.js:13:661) ▲ ✓ Generating static pages (4/4) ▲ ▲ > Export encountered errors on following paths: ▲ /page: / ▲ Error: Command "npm run build" exited with 1

⚡️ The Vercel build (npx vercel build) command failed. For more details see the Vercel logs above. ⚡️ If you need help solving the issue, refer to the Vercel or Next.js documentation or their repositories.

Description

I have a root page that gets a collection and show a list of links.

By default, Next.js and Vercel will make this page static (Vercel uses ISR), which is desirable since I don't want this page making a request to the db every time.

import Link from "next/link";
import { getAllProblems } from "@/server/data/problem-dto";
import { type Problem } from "@/server/db/schema";


export default async function HomePage() {
  const problems = await getAllProblems();
  return (
    <main className="p-10">
      <h1>Problems</h1>
      <ProblemList problems={problems} />
    </main>
  );
}

function ProblemList(props: { problems: Problem[] }) {
  const { problems } = props;
  if (problems.length === 0) {
    return <p>We cannot find any problems.</p>;
  }
  return <ul>{problems.map(createListItem)}</ul>;
}

function createListItem(problem: Problem) {
  return (
    <li key={problem.id}>
      <Link href={`/problems/${problem.id}`}>
        {problem.title}
      </Link>
    </li>
  );
}

But in cloudflare I'm forced to making it run in edge (export const runtime = "edge";) since the build will fail. The response time I get:

  • 50~70 ms when static
  • 300+ ms when running in edge

Even if I explicitly make the page static the build still fails:

import { notFound } from "next/navigation";
import { getProblem } from "@/server/data/problem-dto";

// forcing the page to be static
export const dynamic = "force-static";

export default async function ProblemPage({
  params,
}: {
  params: { id: string };
}) {
  const problemId = parseInt(params.id);
  if (isNaN(problemId)) {
    notFound();
  }
  const problem = await getProblem(problemId);
  if (!problem) {
    notFound();
  }
  return <div>problem: {problem.title}</div>;
}

Reproduction

https://gitlab.com/ChenAlejandro/pages-that-should-be-static-is-forced-to-run-in-edge

Pages Deployment Method

Pages CI (GitHub/GitLab integration)

Pages Deployment ID

No response

Additional Information

I also tried next 14.2.1, getting me the same result (as 14.2.2)

Would you like to help?

  • [X] Would you like to help fixing this bug?

Chenalejandro avatar Apr 20 '24 13:04 Chenalejandro

Same here

dgknca avatar Nov 16 '24 19:11 dgknca

Hello 🙂 Thank you for the issue and apologies for the late reply.

Earlier this year we released our Cloudflare adapter for OpenNext, and we have been continuously investing effort in its improvement since then. Existing deployments can continue to use the next-on-pages tooling, but the Cloudflare adapter for OpenNext is currently stable and recommended for deployment of Next.js applications to Cloudflare.

As such, we will no longer be maintaining next-on-pages. We recently deprecated the package on npm and we plan to archive this repo on Monday Sep 29, 2025. In preparation for archival, we are closing all open issues and PRs.

If you have concerns, please feel free to reply here before the repo is archived (after that, it will no longer be possible to comment) or to reach out to our team on Discord.

Thanks so much for using and contributing to next-on-pages 🧡

dario-piotrowicz avatar Sep 26 '25 23:09 dario-piotrowicz