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.
- 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
| OpenNext | vinext | |
|---|---|---|
| Builds with | next build, then an adapter step | Vite (vite build) |
| Next.js parity | The real Next.js build, so behaviour matches | A reimplementation; its README lists known gaps (full Cache Components, build-time image and font optimisation) |
| Config | wrangler.jsonc and open-next.config.ts | vite.config.ts and cloudflare.config.ts |
| Cloudflare's advice | Keep it for existing projects | Default 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
Step 1: Add the adapter
npm install -D @opennextjs/cloudflare wranglerpnpm add -D @opennextjs/cloudflare wrangleryarn add -D @opennextjs/cloudflare wranglerbun add -D @opennextjs/cloudflare wranglerThen let it set up the project:
Terminalnpx 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.jsoncwith an R2 bucket for the incremental cache, a self-reference service binding and an Images binding, and addedpreview,deployanduploadscripts.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:Terminalnpx wrangler r2 bucket create kb-next-opennext-cacheStep 3: Build and check
Terminalnpx 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 AssetsThe gzipped size is what counts against the Worker size limit. A starter app came to just under 1 MB.
Step 4: Try it locally, then deploy
Terminalnpm run previewnpm run deploypreviewruns the built Worker in Wrangler's local runtime, which is closer to production thannext dev. Secrets go in withnpx wrangler secret put NAME; public settings undervarsinwrangler.jsonc.
Route 2: vinext
Step 1: Check your React version
This tripped us up first.
create-next-app16.4.6 pinned React 19.3.0, and vinext 1.4.6 wants 19.3.1 or newer, sonpm i -D vinextstopped with a peer dependency error. Update React first:npm install react@19.3.1 react-dom@19.3.1pnpm add react@19.3.1 react-dom@19.3.1yarn add react@19.3.1 react-dom@19.3.1bun add react@19.3.1 react-dom@19.3.1Step 2: Run vinext init
Interactively,
npx vinext initasks a few questions. To answer them up front:Terminalnpx 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 scriptPick 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 aVINEXT_KV_CACHEbinding tocloudflare.config.ts. (--cdn-cache=nonetogether with--data-cache=kvis rejected;data-cacheas the CDN option works.)vinext uses Cloudflare's newer
cfCLI and acloudflare.config.tsinstead ofwrangler.jsonc. Yournext devandnext buildkeep working next to it.Step 3: Build, check and deploy
Terminalnpm 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:vinextLog in first with
npx cf auth login, or setCLOUDFLARE_API_TOKENandCLOUDFLARE_ACCOUNT_IDin CI.npm run start:vinextserves the build locally; our test app answered onlocalhost: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.
Related articles
- DeployingDeploy an Astro site to Cloudflare WorkersA static Astro site needs no adapter: a four-line wrangler.jsonc and wrangler deploy. When pages render on request, add @astrojs/cloudflare. Both tested.
- SanityHow to deploy Sanity Studio (hosted or self-hosted)npx sanity deploy puts the Studio on *.sanity.studio for free. Set studioHost for unattended deploys, use a deploy token in CI, or host it yourself.
- Using themes.devFrom website template to live site, step by stepGet the theme from GitHub or as a zip, run it locally, replace the demo content, set SITE_URL and deploy to Cloudflare, Netlify or Vercel.
Still stuck? We answer every message ourselves. Write to us