Migrating Next.js from Vercel to Cloudflare Workers: 2026 Guide
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`.

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

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.
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-runInterpret the output in order:
npm ls --allexposes 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.- A
.noderesult 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. - The source scan finds common direct imports and
requirecalls. Inspect each import path:cryptois not inherently incompatible because Web Crypto is available, while a package that importsnode:fsorchild_processneeds a Worker-compatible alternative. - A successful OpenNext build and local
wrangler devrequest are the first deployment compatibility check. A successfulwrangler deploy --dry-runchecks 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 Message | What It Means | Next Check |
|---|---|---|
Dynamic Code Evaluation ... is not allowed | A 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 error | The 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 exhaustion | The 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 message | Worker 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 occurred | Cloudflare 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.
{
"$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:
npx opennextjs-cloudflare build
npx wrangler dev --local
npx wrangler deploy --dry-run
npx wrangler deployAdd 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.
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.
Get the Weekly SMB AI & SaaS Brief
Practical software benchmarks, prompt templates, and ROI breakdowns delivered every Tuesday. No fluff, unsubscribe anytime.