If you're putting a Next.js app on Cloudflare in 2026, the build is the easy half. The interesting half is that your app no longer runs on Node — it runs on the Workers runtime, a V8 isolate with a different set of rules. Most "it works locally, 500s in production" surprises trace back to that one fact.
This chapter is the mental model I wish I'd had going in: which path to pick, where each part of a Next app actually executes, the three categories of wall you'll hit, and how to read a failure so you can fix your specific case. Your exact errors will differ from mine — that's the point. Learn the shape and you can debug any of them.
First decision: Pages or Workers?
Cloudflare has two ways to host a Next.js app, and in 2026 the guidance has flipped from what most tutorials still say.
The older path — Cloudflare Pages with the Next.js preset — rides an adapter (@cloudflare/next-on-pages) that is now in maintenance mode and lags the Next.js release line. If your notes still say "use the Pages Next.js framework preset," they're out of date. The supported 2026 path is Cloudflare Workers + the OpenNext adapter (@opennextjs/cloudflare). Cloudflare itself now steers new projects to Workers; Pages is in maintenance for new work.
The takeaway that outlives the version numbers: check what the adapter supports against the Next version you're on, before you write a line of deploy config. Adapter lag is the single most common source of "the tutorial lied to me."
The mental model: where does each part run?
Once you're on Workers, every confusing error gets clearer if you can place where the code runs. A deployed Next-on-Workers app has three execution zones:
Three zones, three different rule sets:
- Static assets — prerendered at build time (in Node, on your machine or CI), then served as files. Anything that happened here is already finished and safe.
- The Worker — your SSR and route handlers, running in a V8 isolate. This is not Node. No filesystem, a restricted set of Node APIs, and — the big one — no runtime code evaluation.
- The browser — hydration and client components. Full DOM, and
evalis allowed again here. Things that can't run in the Worker can often run in the browser instead.
Hold onto that map. Every wall below is really "I assumed this code was running in a zone where it wasn't."
The three categories of wall
Your specific errors will be unique, but they almost always fall into one of three buckets.
Wall 1 — Runtime mismatch (Node-isms in an edge world)
The Worker is a V8 isolate, not a Node process. Code that assumes Node — fs, some crypto paths, native addons, certain streams, or middleware that expects the Node runtime — won't run at the edge.
A 2026-specific instance of this: Next moved middleware toward a Node-capable runtime, while edge adapters still require the edge runtime for it. You can get whipsawed between "X only supports Node" and "the adapter only supports edge." The general fix is to make the middleware genuinely edge-safe (pure request/URL logic, web APIs only) and run it on the edge runtime the adapter expects.
What this looked like for me: Next 16 renamed
middleware.tsto a Node-defaultproxy.ts; the adapter only supported edge middleware; forcing edge onproxy.tswas itself rejected. The escape was the still-supported legacymiddleware.tson the edge runtime — kept deliberately minimal (host/redirect logic, no Node APIs).
How to read it: the error names a runtime ("Node.js … not supported," "edge runtime required"). Ask which zone is this code in, and which runtime does that zone allow? Move the code or change its runtime to match.
Wall 2 — Dynamic code evaluation (eval is banned at the edge)
This is the subtle one. Cloudflare Workers forbid eval and new Function at runtime — it's a platform security rule, not a config you can flip. Any library that generates and executes code at request time dies in the Worker. Common culprits: some template engines, certain schema/validation compilers, and content pipelines that compile markup to a function and run it on the server.
The tell is distinctive: it works in next dev (Node, eval allowed), it works after build, but the specific routes 500 only on the Workers runtime.
The general fix is to move the codegen to build time, where it runs in Node and eval is legal. For anything that renders content (MDX, etc.), that means forcing the route to prerender instead of server-render on demand:
// the content route
export const dynamicParams = false; // unknown paths 404, don't render on demand
export const dynamic = "force-static"; // prerender at build, in Node
Now the dynamic step happens during the build, the browser handles hydration, and the Worker only serves the finished output.
What this looked like for me: this site's markdown pipeline compiles MDX to a function and rehydrates it with
new Function. Content pages 500'd only onworkerd. Forcing the content routes static fixed it — and "publish = rebuild" was already true for a git-based site.
Wall 3 — The caching / rendering model is different
Adapters re-implement Next's caching (ISR, the data cache, prerender output) on top of Cloudflare primitives, and the defaults may not match your app. A frequent shape: pages you thought were prerendered still try to render on demand, because the adapter's incremental cache defaults to a no-op — which then re-triggers Wall 2 or just errors.
The general principle: after you choose static vs. dynamic in Next, make sure the adapter is configured to serve it that way. For a pure content/prerendered site, point the adapter at its read-only static cache so prerendered pages are served as assets with nothing to compute.
What this looked like for me (OpenNext specifically): the fix was wiring the static-assets incremental cache —
// open-next.config.ts import { defineCloudflareConfig } from "@opennextjs/cloudflare"; import cache from "@opennextjs/cloudflare/overrides/incremental-cache/static-assets-incremental-cache"; export default defineCloudflareConfig({ incrementalCache: cache });Its own docs say it's for apps that "ONLY want to serve prerendered data." That's a markdown site.
A debugging flow you can reuse
When a route misbehaves on Workers but not in dev, walk the zones:
The meta-skill: reproduce on the real runtime before you debug. next dev runs on Node and will happily hide all three walls. Use the adapter's local preview (for OpenNext, opennextjs-cloudflare preview, which runs workerd — the actual Workers engine) so failures show up on your machine, not in production.
The bonus wall: the bug that's always yours
Not every wall is the platform's. After the runtime issues were solved, my whole site started 301-redirecting to localhost. Cause: my middleware derived its canonical hostname from an environment variable, and a leftover dev value in .env.local overrode the production value at build time (framework env-file precedence is a classic foot-gun). The deployed middleware faithfully redirected the entire internet to my laptop.
The lesson is general: a per-environment constant that must be correct in production should not be quietly resolvable from a dev env file. I deleted the dev override and hardcoded the value where it has exactly one correct answer. When something breaks right after a deploy, check your own configuration precedence before you blame the platform.
The scoreboard
| Path | Cloudflare Workers + OpenNext adapter (not Pages) |
| The one fact | Workers = V8 isolate, not Node: no eval, limited Node APIs |
| Wall 1 | Runtime mismatch → make edge code edge-safe |
| Wall 2 | eval/codegen banned → move it to build (force-static) |
| Wall 3 | Adapter cache defaults → configure for your static/dynamic mix |
| Debug rule | Reproduce on the real runtime (workerd preview), then place the zone |
Getting the app running on Workers is one half of going live. The other half — moving a domain from a registrar onto Cloudflare without downtime, and the cache trap that makes a healthy launch look broken — is the next chapter.