Skip to content

Deploy Next.js to Cloudflare Workers: OpenNext or vinext

Two routes, both built and dry-run deployed on Next.js 16: OpenNext for the real Next.js build, vinext for new apps on Vite. Which to pick and the gotchas.

Updated 23 November 2026Tested with
  • Next.js 16.4.6
  • @opennextjs/cloudflare 1.20.18
  • vinext 1.4.6
  • Wrangler 4.166.0

You can run a Next.js app on Cloudflare Workers in two ways. OpenNext (@opennextjs/cloudflare) takes the output of next build and turns it into a Worker. vinext is Cloudflare's reimplementation of the Next.js APIs on Vite, which Cloudflare's guide now recommends for new projects. We built a fresh Next.js 16.4.6 app both ways, up to a successful dry-run deploy, and describe both below. Our own Next.js + Sanity templates use OpenNext.

Which one to use

OpenNextvinext
Builds withnext build, then an adapter stepVite (vite build)
Next.js parityThe real Next.js build, so behaviour matchesA reimplementation; its README lists known gaps (full Cache Components, build-time image and font optimisation)
Configwrangler.jsonc and open-next.config.tsvite.config.ts and cloudflare.config.ts
Cloudflare's adviceKeep it for existing projectsDefault for new projects

Our take: if the app already runs on OpenNext, or you bought one of our templates, stay on OpenNext. For a new app, try vinext and run npx vinext check on it early, so you find unsupported features before you depend on them.

Route 1: OpenNext

  1. Step 1: Add the adapter

    npm install -D @opennextjs/cloudflare wrangler

    Then let it set up the project:

    Terminal
    npx opennextjs-cloudflare migrate⚙️  Creating open-next.config.ts...⚙️  Creating .dev.vars file...⚙️  Creating public/_headers file...⚙️  Updating package.json scripts...🎉 OpenNext Cloudflare adapter complete!

    It wrote a wrangler.jsonc with an R2 bucket for the incremental cache, a self-reference service binding and an Images binding, and added preview, deploy and upload scripts.

  2. Step 2: Create the cache bucket

    Pages rebuilt by ISR or revalidation are stored in R2. The bucket name is in wrangler.jsonc; create it once:

    Terminal
    npx wrangler r2 bucket create kb-next-opennext-cache
  3. Step 3: Build and check

    Terminal
    npx opennextjs-cloudflare buildWorker saved in `.open-next/worker.js` 🚀OpenNext build complete.npx wrangler deploy --dry-runTotal Upload: 4653.86 KiB / gzip: 989.24 KiBBinding                                                Resourceenv.NEXT_INC_CACHE_R2_BUCKET (kb-next-opennext-cache)  R2 Bucketenv.WORKER_SELF_REFERENCE (kb-next)                    Workerenv.IMAGES                                             Imagesenv.ASSETS                                             Assets

    The gzipped size is what counts against the Worker size limit. A starter app came to just under 1 MB.

  4. Step 4: Try it locally, then deploy

    Terminal
    npm run previewnpm run deploy

    preview runs the built Worker in Wrangler's local runtime, which is closer to production than next dev. Secrets go in with npx wrangler secret put NAME; public settings under vars in wrangler.jsonc.

Route 2: vinext

  1. Step 1: Check your React version

    This tripped us up first. create-next-app 16.4.6 pinned React 19.3.0, and vinext 1.4.6 wants 19.3.1 or newer, so npm i -D vinext stopped with a peer dependency error. Update React first:

    npm install react@19.3.1 react-dom@19.3.1
  2. Step 2: Run vinext init

    Interactively, npx vinext init asks a few questions. To answer them up front:

    Terminal
    npx vinext init --platform=cloudflare --cdn-cache=data-cache --data-cache=kv --image-optimization=none    ✓ Generated vite.config.ts    ✓ Generated cloudflare.config.ts    ✓ Configured deploy:vinext script

    Pick a data cache. We first ran it with --data-cache=none, and the deploy then refused: the app uses caching, and "Production deployments need a persistent cache backend". The KV data cache adds a VINEXT_KV_CACHE binding to cloudflare.config.ts. (--cdn-cache=none together with --data-cache=kv is rejected; data-cache as the CDN option works.)

    vinext uses Cloudflare's newer cf CLI and a cloudflare.config.ts instead of wrangler.jsonc. Your next dev and next build keep working next to it.

  3. Step 3: Build, check and deploy

    Terminal
    npm run build:vinext  Build complete.npx vinext-cloudflare deploy --skip-build --dry-run  Router:  App Router  Dry run complete. No build or deploy performed.npm run deploy:vinext

    Log in first with npx cf auth login, or set CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID in CI. npm run start:vinext serves the build locally; our test app answered on localhost:4173.

If you don't need a server

A Next.js site with output: "export" in next.config.ts builds to plain files in out/. Then you need neither adapter: deploy it like a static Astro site, with assets.directory set to ./out. Deploying Astro to Cloudflare has that config. You lose what needs a server: route handlers, middleware, ISR and on-demand revalidation.

Our Next.js + Sanity templates

Each one ships with wrangler.jsonc and open-next.config.ts ready, using the R2 incremental cache. Give the Worker your own name (it appears twice: the top-level name and the self-reference service), create the bucket, put the three secrets in with wrangler secret put, then pnpm deploy:cf. The README's Deploy section lists every variable. Vercel works too: import the repository and it recognises Next.js.

Questions

Does Next.js work on Cloudflare Pages?

The older next-on-pages route targeted Pages and the edge runtime. Both OpenNext and vinext target Workers and the Node.js compatibility layer, which supports far more of Next.js. Use Workers.

Can I deploy Next.js without Vercel?

Yes: Cloudflare with one of the two routes here, any Node.js host with next start or output: "standalone", or a static host with output: "export".

Why does my revalidated page not update on Cloudflare?

Check that the R2 bucket exists and is bound as NEXT_INC_CACHE_R2_BUCKET, and that WORKER_SELF_REFERENCE points to the Worker's own name. If you renamed the Worker but not the service binding, revalidation calls the wrong Worker.

Was this page helpful?

Still stuck? We answer every message ourselves. Write to us

This page is built from UI Pro parts: the docs article block (docs-quernly) with the code, terminal, install command, steps, contents and feedback components. They ship in the next UI Pro release; the install command and the contents rail are free.