0xOX0X
Cloud & SaaS

Migrating Next.js from Vercel to Cloudflare Workers: 2026 Guide

Quick Answer

OpenNext can package supported Next.js App Router applications as a Cloudflare Worker with static assets; this is a Workers deployment, not a Cloudflare Pages deployment. Validate native dependencies, Node.js API usage, database connectivity, and build output locally before using `wrangler deploy`.

By Elena RostovaUpdated 2026-11-225 min read
3D isometric tech illustration representing Next.js edge migration from Vercel to Cloudflare Workers

OpenNext can package supported Next.js App Router applications as a Cloudflare Worker with static assets. This is a Workers deployment, not a Cloudflare Pages deployment: the wrangler.json and wrangler deploy workflow below publish a Worker plus its asset directory.

Before moving production traffic, compare your application against the OpenNext Cloudflare supported-features documentation and Cloudflare’s Workers runtime documentation. Support changes with Next.js and OpenNext releases, so do not treat feature support as complete parity with Vercel.

Cloudflare Workers and Vercel Runtime Differences

Cloudflare Workers and Vercel Runtime Differences - Migrating Next.js from Vercel to Cloudflare Workers: 2026 Guide

Vercel Functions use Node.js runtimes where supported native dependencies may work when they are built for the deployed environment; review Vercel’s native dependency guidance for packaging constraints. Cloudflare Workers run on the Workers runtime and support Web-standard APIs plus selected Node.js APIs through compatibility features such as nodejs_compat.

Do not assume that fs, child processes, native .node binaries, headless browsers, or every Node.js package will run in a Worker. Move image processing, browser automation, and CPU-heavy jobs to a service designed for that workload when compatibility testing identifies a dependency gap.

Cloudflare publishes its current network and runtime behavior in the Workers documentation. Avoid capacity assumptions based on a fixed number of locations or a claim that cold starts are eliminated; observed startup and latency depend on the application, traffic pattern, and Cloudflare’s current platform behavior.

Next.js Worker Compatibility Verification

Run these checks before changing application code. depcheck can identify unused or missing dependencies, but it cannot establish Worker compatibility or reliably identify native extensions.

bash
npm ls --all
find node_modules -type f -name '*.node' -print
rg -n --glob '!node_modules/**' "(node:)?(fs|child_process|cluster|dgram|net|tls|worker_threads)|require\(|from\s+['\"]" src app pages lib
npx opennextjs-cloudflare build
npx wrangler dev --local
npx wrangler deploy --dry-run

Interpret the output in order:

  1. npm ls --all exposes the dependency tree. Inspect packages that pull in native binaries, Node-only SDKs, or database drivers rather than assuming their top-level package names are safe.
  2. A .node result is a native addon and requires replacement, externalization to a compatible service, or a separately supported runtime. It is not executable in the Workers runtime.
  3. The source scan finds common direct imports and require calls. Inspect each import path: crypto is not inherently incompatible because Web Crypto is available, while a package that imports node:fs or child_process needs a Worker-compatible alternative.
  4. A successful OpenNext build and local wrangler dev request are the first deployment compatibility check. A successful wrangler deploy --dry-run checks Wrangler packaging without publishing.

For database access, direct PostgreSQL connections are not universally impossible, but traditional long-lived TCP pools are often a poor fit for isolate-based request handling. Verify the driver and connection model against Cloudflare’s database connectivity guidance. HTTP- or WebSocket-based drivers, a provider pooler, or Cloudflare Hyperdrive may be appropriate. See also Supabase vs Neon Postgres: Real Pricing and Limits Compared.

Cloudflare Workers Error Isolation Paths

Use verification before applying a workaround. Review invocation logs with wrangler tail, reproduce in wrangler dev, and inspect the dependency import path before enabling compatibility flags or replacing packages.

Log / Error MessageWhat It MeansNext Check
Dynamic Code Evaluation ... is not allowedA bundled dependency uses eval, new Function, or similar dynamic execution.Locate the package with the build trace and reproduce with npx wrangler dev --local; replace or reconfigure that dependency.
Buffer is not defined or a missing Node module errorThe code expects a Node global or API that is not available under the active compatibility settings.Identify the importing file with rg and confirm whether the API is supported by the Node.js compatibility matrix.
Database connection resets, socket errors, or pool exhaustionThe driver, network path, or pooling strategy is unsuitable for the request pattern.Reproduce one request in wrangler dev, inspect the driver transport, and review Worker invocation logs before changing drivers or adding Hyperdrive.
Worker error code 1102 or a CPU-limit messageWorker CPU time was exceeded.Run npx wrangler tail <worker-name> --format pretty and inspect the Worker dashboard’s invocation errors; reduce synchronous work or move it to an appropriate asynchronous service.
HTTP 524 A timeout occurredCloudflare timed out waiting for an upstream origin response; it is not proof that Worker CPU time was exceeded.Check the cf-ray value, origin logs, and Worker logs. If the Worker fetched an origin, test that origin directly and inspect its response time.

For every path, fix the root cause first: remove unsupported dependencies, change the database transport, or move unsuitable work outside request handling. nodejs_compat can help supported Node.js APIs, but it does not make native addons, filesystem access, or child processes available.

OpenNext Cloudflare Worker Deployment Configuration

Install the OpenNext Cloudflare adapter and Wrangler according to the OpenNext installation guide and Wrangler configuration reference. Use one complete wrangler.json file like this; replace my-nextjs-worker and the compatibility date with values appropriate for your project.

json
{
  "$schema": "node_modules/wrangler/config-schema.json",
  "name": "my-nextjs-worker",
  "main": ".open-next/worker.js",
  "compatibility_date": "2026-01-01",
  "compatibility_flags": [
    "nodejs_compat"
  ],
  "assets": {
    "directory": ".open-next/assets",
    "binding": "ASSETS"
  },
  "observability": {
    "enabled": true
  }
}

Build and test the same artifact that will be deployed:

bash
npx opennextjs-cloudflare build
npx wrangler dev --local
npx wrangler deploy --dry-run
npx wrangler deploy

Add KV, R2, D1, Hyperdrive, or cache bindings only when the OpenNext version and application configuration require them. Their binding names and setup must match the adapter documentation; do not add an unused KV namespace merely because an application uses Next.js caching.

Cloudflare Workers Limits, Billing, and Migration Decision

Workers limits, including script size, CPU time, subrequests, and request behavior, vary by plan, configuration, and product changes. Check the current Workers limits documentation before approving a migration. Test the generated artifact with the intended account and plan rather than relying on fixed bundle-size or CPU-duration figures.

Cloudflare Workers billing is generally based on plan allowances and measured usage such as requests and CPU time; static asset delivery and related services have separate product terms. Vercel pricing is likewise usage- and plan-dependent, with applicable charges described in its pricing documentation. Model actual traffic, bandwidth, function execution, storage, and database costs using each provider’s current calculator and invoice data.

Migrate when the OpenNext feature set covers your routes, the Worker build passes local and dry-run checks, and your database and background-work architecture fit the Workers runtime. Stay with, or retain, a Node-oriented platform for routes that require native binaries, unrestricted filesystem access, child processes, or runtime behavior that has not passed a production-equivalent Worker test.

Share this article

Frequently Asked Questions

Can I use Next.js Server Actions on Cloudflare Pages?

Yes. Server Actions are supported when deploying with Open-Next v3+ on Cloudflare Workers/Pages, provided your action functions do not invoke unsupported native Node.js C++ modules.

How does dynamic image optimization work after migrating off Vercel?

Cloudflare does not automatically run Vercel's default image optimization API. You can route images through Cloudflare Images, set up custom Workers for transformations, or use unoptimized static images.

Do I need to change my database connection code when migrating to Cloudflare?

If you connect to databases over standard TCP sockets (like default node-postgres), you must update your setup to use HTTP drivers, WebSockets, or Cloudflare Hyperdrive to pool connections within V8 isolates.

Free Weekly Dispatch

Get the Weekly SMB AI & SaaS Brief

Practical software benchmarks, prompt templates, and ROI breakdowns delivered every Tuesday. No fluff, unsubscribe anytime.