vinext takes a different route. It's an open-source Vite plugin from Cloudflare that reimplements the Next.js API on top of Vite. Your app/ and pages/ directories, next/link, next/navigation, Server Components, Server Actions, middleware and ISR all keep working. The output is a Vite build. It can reach Vercel, Netlify, AWS, Deno Deploy or a plain Node server through Nitro, but Cloudflare Workers is where vinext works best. Cloudflare builds vinext, and Workers is the target it was designed around.
This guide takes a Next.js app from your laptop to a live URL on Cloudflare's network. It covers migrating an existing project, running it locally, deploying, environment variables, databases and caching, a custom domain and automatic deploys.
Why vinext works best on Workers
- The same runtime in dev and production. The vinext dev server runs your server code in workerd, the runtime behind Workers, so what works on localhost works once it's deployed.
- One command to deploy.
@vinext/cloudflarechecks your setup, builds the app and uploads it in one step. You don't need to adapt any build output. - Cloudflare resources in any Server Component. D1, KV and R2 are one import away through
cloudflare:workers, with no custom Worker entry. - Image optimisation built in.
next/imageis resized by Cloudflare Images without any extra setup. - A shared cache built for ISR. The Workers Response Store shares cached pages and data across the network, and it can pre-warm your busiest routes before each release.
- Previews and deploys on every push. Each pull request gets its own Worker Preview, and Workers Builds redeploys your app from Git without a CI pipeline to maintain.
On other platforms you still get the core Next.js API, but you have to put these pieces together yourself.
What you'll need
- A Next.js 16 app, using either the App Router or the Pages Router. vinext targets the latest Next.js only.
- Node.js 22.23+ or 24.22+. vinext needs Node 22 or later, and the
cfCLI it deploys with only supports these versions. If you use nvm, pin the version in.nvmrcso everyone on the team gets it. - A free Cloudflare account
- About 30 minutes
Heads up: vinext is young (v1.4 at the time of writing) and doesn't cover every corner of Next.js. Run the compatibility check in Step 1 before you commit. If you rely on something vinext doesn't support yet, OpenNext is the more mature way to run Next.js on Cloudflare.

Starting from scratch?
If you don't have an app yet, Cloudflare's project creator scaffolds a Next.js app that's already set up for vinext and Workers:
npm create cloudflare@latest -- my-next-app --framework=next --variant=vinext cd my-next-app npm run dev # local dev server npm run deploy # build and ship to Workers
Without --variant=vinext, the creator asks which Next.js adapter you want. vinext is the recommended default, and the other choice is OpenNext. The project comes without a shared cache, which you can add later (see Part 5).
That's the whole setup. Skip to Part 4 for environment variables, databases, domains and automatic deploys. The rest of this guide is for moving an existing Next.js app.
Part 1: Migrate your existing app
Step 1: Check compatibility
From your project root, run:
npx vinext check
This scans your app for APIs, config options and dependencies vinext doesn't support, without changing any files. Read the report closely. Anything marked unsupported will break, so decide now whether you can work around it.
Things that commonly show up:
- Native Node addons such as
sharp,@resvg/resvg-jsor@napi-rs/canvas. Workers can't load these. - Partial Prerendering and
cacheComponents, which aren't fully supported yet. - Webpack or Turbopack config in
next.config. vinext uses Vite, so these are ignored. - Vercel-only features such as
@vercel/ogon Vercel's infrastructure, or AMP.

Step 2: Initialise vinext
npx vinext init --platform=cloudflare
--platform=cloudflare skips the deployment-target prompt. The command:
- Runs the compatibility check again
- Installs
vinext,@vinext/cloudflare,react-server-dom-webpack, Vite 8,@vitejs/plugin-rsc, v2 of the Cloudflare Vite plugin and thecfCLI. If your React version is too old forreact-server-dom-webpack, it upgradesreactandreact-domtoo. - Adds
"type": "module"topackage.jsonand renames CommonJS config files such aspostcss.config.jsto.cjs - Adds the
dev:vinext,build:vinext,start:vinextanddeploy:vinextscripts - Generates
vite.config.tsandcloudflare.config.ts
It then asks three questions:
- "Pre-render all static routes after build?" Answer No for now. A Cloudflare deploy doesn't serve pre-rendered pages unless you use the Static Assets cache, so it only adds build time.
- "Enable caching?" Answer Yes if you use ISR,
revalidateor"use cache", and choose Workers Response Store, the default. Part 5 explains what that adds. Choosing now is much easier than adding a cache by hand later. - "Enable cache pre-warm during deploy?" Answer No for now. It only matters once you have a cache and a custom domain.
This step is non-destructive. It doesn't touch next.config, tsconfig.json or your source files, and npm run dev still starts Next.js. You can run both side by side while you migrate.
Tip: Commit (or stash) your work before running
init, sogit diffshows you exactly what changed.
Gotcha: init stops if you already have a
wrangler.toml,wrangler.jsonorwrangler.jsonc. That's common if the app ran on OpenNext before, or was set up with an early vinext beta. If the file configures this app, rename it (for example towrangler.old.jsonc), runinit, copy its bindings (KV, D1, R2, vars) into the newcloudflare.config.ts, then delete the old file. If it belongs to a different Worker in the same repo, runinitwith--ignore-wrangler-config. To keep a Wrangler-based setup, use--legacy-wrangler-cloudflare-init. Note that the rest of this guide assumescloudflare.config.ts.

Step 3: Look at the generated config
Open vite.config.ts. For an App Router project where you skipped caching, it looks like this:
import { defineConfig } from "vite"; import vinext from "vinext"; import { cloudflare } from "@cloudflare/vite-plugin"; import { imagesOptimizer } from "@vinext/cloudflare/images/images-optimizer"; export default defineConfig({ plugins: [ vinext({ images: { optimizer: imagesOptimizer() }, }), cloudflare({ // The Worker runs in the RSC environment, with SSR as a child. viteEnvironment: { name: "rsc", childEnvironments: ["ssr"] }, }), ], });
imagesOptimizer() is there by default. It resizes next/image images at request time with Cloudflare Images (pass --image-optimization=none to init if you don't want it). If you enabled caching, you'll also see a cache: option here.
Gotcha: Don't add
@vitejs/plugin-rsctopluginsyourself.initinstalls it, and vinext registers it automatically when it finds anapp/directory. Registering it twice breaks the build.
Then open cloudflare.config.ts. This describes your Worker: its name, entry point, runtime flags and the resources it can reach:
import { bindings, defineConfig, defineWorker } from "cf/config"; export default defineConfig({ worker: defineWorker({ name: "my-next-app", entrypoint: "vinext/server/fetch-handler", compatibilityDate: "2026-10-31", compatibilityFlags: ["nodejs_compat"], assets: { htmlHandling: "none", notFoundHandling: "none", runWorkerFirst: ["/*", "!/_next/static/*", "!/*/_next/static/*"], }, env: { ASSETS: bindings.assets(), IMAGES: bindings.images(), }, }), });
The name becomes your Worker's name and its default URL. Change it now if you want something other than your package.json name, or pass --name to init. runWorkerFirst sends every request through your app, so middleware and routing run, except hashed files under _next/static/, which are served straight from the CDN.
Two more bits of housekeeping:
- TypeScript: add
".cloudflare/types"toincludeintsconfig.json. Binding types are generated there during dev and build. .gitignore: make suredist/,.vinext/(the downloaded font cache) and.cloudflare/are ignored. If you lint witheslint-config-nextand override its ignore list, adddist/**there too, ornpm run lintwill scan the built bundles after your first build.

Part 2: Run it locally
Step 4: Start the vinext dev server
npm run dev:vinext
Open http://localhost:3001. vinext uses port 3001 so it doesn't clash with next dev on 3000.
Your server code runs inside workerd, the same runtime Cloudflare uses in production, so a page that works here is very likely to work once deployed. Click through every important route: auth flows, forms that call Server Actions, API routes and anything behind middleware.

Step 5: Fix what breaks
Most apps run straight away. These are the usual exceptions and how to fix them:
Run npx vinext check again after each fix.
Step 6: Build and preview production
npm run build:vinext npm run start:vinext
The first command creates an optimised production build in dist/. The second runs vite preview, which serves that build in workerd at http://localhost:4173. Test the production build here, because some bugs only show up once code is minified and bundled.

Part 3: Deploy to Cloudflare Workers
Step 7: Log in to Cloudflare
npx cf auth login
A browser window opens and asks you to authorise the CLI. Approve it and go back to the terminal.
Next, tell the deploy tool which account to use. Copy your Account ID from the dashboard URL (dash.cloudflare.com/<account-id>), then either add it to the top level of cloudflare.config.ts:
export default defineConfig({ accountId: "<your-account-id>", worker: defineWorker({ /* ... */ }), });
…or export it as an environment variable:
export CLOUDFLARE_ACCOUNT_ID=<your-account-id>
The account ID isn't a secret, but the environment variable is useful if your team deploys to different accounts.

Step 8: Deploy
npm run deploy:vinext
This runs vinext-cloudflare deploy (you can also call it directly with npx @vinext/cloudflare deploy). The one command checks your setup, builds the app and uploads it to Workers. When it finishes, it prints your live URL:
https://my-next-app.<your-subdomain>.workers.dev
Want to check what will happen first? Add --dry-run to build and validate without uploading.

Step 9: Check the live app
Open the URL. Your Next.js app is now running on Cloudflare's network, served from the data centre closest to each visitor, with no server to manage.
In the dashboard under Workers & Pages → my-next-app, you'll find request metrics, live logs and a Deployments tab. If a release goes wrong, you can roll back from that tab in one click.

Part 4: Environment variables and secrets
vinext loads .env files the same way Next.js does. It reads, in order of priority, the existing process.env, then .env.production.local, .env.local, .env.production and .env. Build, start and deploy all run in production mode.
There are two kinds of variable to handle:
1. Public variables (NEXT_PUBLIC_*). These are baked into the JavaScript bundle at build time. They must exist on the machine that runs deploy, either in .env.production or in your CI environment. Setting them in the Cloudflare dashboard afterwards does nothing.
2. Server-only variables, meaning anything without the prefix, secret or not: backend URLs, database URLs, API keys, auth secrets. These are not baked into the build. Your .env files feed them to dev:vinext and start:vinext locally, but the deployed Worker never sees them. This is the most common "works locally, breaks in production" bug, so give each one a value on the Worker.
Declare them in cloudflare.config.ts. Use bindings.text() for plain values and bindings.secret() for anything sensitive:
env: { ASSETS: bindings.assets(), IMAGES: bindings.images(), API_BASE_URL: bindings.text("https://api.example.com"), // plain value, lives in the config AUTH_SECRET: bindings.secret(), // value set in the dashboard },
Set each secret's value under Workers & Pages → my-next-app → Settings → Variables and Secrets → Add, using the Secret type. Keep plain values in the config rather than the dashboard, because the config is the source of truth on every deploy.
With the nodejs_compat flag, your code reads both with process.env.API_BASE_URL and process.env.AUTH_SECRET, as it would in Next.js. You don't need to change any app code.
Warning: Never prefix a secret with
NEXT_PUBLIC_. Anything with that prefix ends up in the browser, where anyone can read it.

Part 5: Add a database, storage and caching
Bindings: D1, KV, R2 and more
On Workers, Cloudflare resources are connected to your app as bindings. Add them to env in cloudflare.config.ts:
env: { ASSETS: bindings.assets(), DB: bindings.d1({ name: "my-app-db" }), // SQL database UPLOADS: bindings.r2({ name: "my-app-uploads" }), // file storage SESSIONS: bindings.kv(), // key-value store },
Then use them from any Server Component, route handler or Server Action. You don't need a custom Worker entry:
// app/posts/page.tsx import { env } from "cloudflare:workers"; export default async function PostsPage() { const { results } = await env.DB.prepare( "SELECT id, title FROM posts ORDER BY created_at DESC" ).all(); return ( <ul> {results.map((post) => ( <li key={post.id}>{post.title}</li> ))} </ul> ); }
Binding types are generated into .cloudflare/types during dev and build. Because you added that folder to tsconfig.json in Step 3, env.DB is fully typed. In CI, run npx cf workers types before a standalone tsc check, because that folder isn't committed.

Make ISR and "use cache" work across the network
Out of the box, vinext caches in memory. That's fine locally, but on Workers each instance has its own memory, so revalidate and "use cache" results aren't shared. You have two ways to share the cache.
Option A: Workers Response Store (recommended). This is what init sets up when you answer "Yes" to caching. You can also ask for it directly with npx vinext init --platform=cloudflare --cdn-cache=response-store. It caches both whole pages and data, backed by R2 and a Durable Object. By default it runs as a second Worker (my-next-app-response-store) that your app reaches through a service binding, so it adds three things to your setup:
vite.config.tsgetscache: responseStoreAdapter(), andcloudflare.config.tsgets the cache Worker's config.- A
deploy:response-storescript. - A one-time extra deploy step. The cache Worker has to exist before your app is deployed, and
deploy:vinextnever deploys it for you:
npm run build:vinext npm run deploy:response-store # first time, and whenever the cache package or its config changes npm run deploy:vinext
R2 must be enabled on your Cloudflare account (Dashboard → R2) before that first deploy. If you'd rather not run a second Worker, choose the self-contained mode when init asks, or pass --response-store-mode=self-contained. Everything is then deployed inside your app's Worker.
Option B: Workers KV for the data cache. This is simpler, with no second Worker, but it only covers fetch, "use cache" and unstable_cache, not whole pages. KV is also eventually consistent, so a revalidation can take up to a minute to reach every location. Pass --data-cache=kv to init, or add it by hand.
In vite.config.ts:
import { kvDataAdapter } from "@vinext/cloudflare/cache/kv-data-adapter"; // ...plus the vite, vinext, cloudflare and imagesOptimizer imports from Step 3 export default defineConfig({ plugins: [ vinext({ cache: { data: kvDataAdapter() }, images: { optimizer: imagesOptimizer() }, }), cloudflare({ viteEnvironment: { name: "rsc", childEnvironments: ["ssr"] } }), ], });
And in cloudflare.config.ts, add the binding the adapter looks for by default:
env: { ASSETS: bindings.assets(), IMAGES: bindings.images(), VINEXT_KV_CACHE: bindings.kv(), },
With either option, revalidateTag() and revalidatePath() now clear the cache for every visitor, not just one instance. The vinext caching guide covers the other adapters, such as Workers Cache for page responses and Static Assets for pre-rendered pages.
Images and fonts
-
next/imageworks.initturns on the Cloudflare Images optimiser by default:imagesOptimizer()invite.config.tsplusIMAGES: bindings.images()incloudflare.config.ts. Local images are resized and converted to AVIF or WebP at request time, not at build time. If you removed it or raninitwith--image-optimization=none, add both back to turn it on:// vite.config.ts import { imagesOptimizer } from "@vinext/cloudflare/images/images-optimizer"; vinext({ images: { optimizer: imagesOptimizer() } }); -
next/font/googleworks and is self-hosted. vinext downloads the font files at build time and serves them from your own domain under/_next/static/_vinext_fonts/, with fallback metrics to reduce layout shift. If the download fails, it falls back to Google's CDN.next/font/localworks too, but its@font-faceCSS is injected at runtime rather than extracted at build time.
Part 6: Use your own domain
The domain must already be on your Cloudflare account, with its DNS managed by Cloudflare. Add it to the Worker:
worker: defineWorker({ name: "my-next-app", domains: ["myapp.com"], // ... }),
Redeploy with npm run deploy:vinext. Cloudflare creates the DNS record and issues an SSL certificate for you, which usually takes a minute or two.
Tip: If you set up a page cache (Response Store or Workers Cache) and a custom domain, you can add
--traffic-aware-warm-cacheto your deploy command. vinext then reads your zone analytics, pre-warms the cache for your most-visited routes, and only then switches traffic to the new version, so visitors don't hit a cold cache after a release. The API token it deploys with also needs Zone → Analytics → Read and Zone → Zone → Read for that domain.

Part 7: Deploy automatically on every push
Running npm run deploy:vinext by hand works, but you don't have to. Workers Builds, Cloudflare's built-in Git integration, builds and deploys your Worker every time you push. You don't need a CI file, and you don't need an API token, because Cloudflare handles authentication for you.
Connect your repository with Workers Builds
- Push your project to GitHub or GitLab.
- In the dashboard, open Workers & Pages → my-next-app → Settings → Builds and select Connect. If you haven't deployed yet, you can create the Worker from Workers & Pages → Create → Import a repository instead.
- Choose the repository and the production branch (usually
main), then set the commands:- Build command: leave it empty. The deploy command builds the app.
- Deploy command:
npx @vinext/cloudflare deploy - Non-production branch deploy command:
npx @vinext/cloudflare previews deploy
- Under Build variables and secrets, add every
NEXT_PUBLIC_*value your build needs. These are only available at build time. They're separate from the runtime Variables and Secrets you set on the Worker in Part 4. - Save, then push a commit.
From then on, every push to main goes to production. Pushes to other branches and pull requests build a Worker Preview: a separate URL that runs the branch's code next to your live Worker, without touching production traffic. On GitHub, Cloudflare posts the preview link on the pull request. Build logs and history appear on the Worker's Deployments tab, next to the rollback button from Step 9.
Gotcha: The
nameincloudflare.config.tsmust match the Worker you connected, or the build fails. Workers Builds also needs Node 22.23 or later, so commit the.nvmrcfrom the requirements (or set aNODE_VERSIONbuild variable) so it doesn't build on an older default.

Optional: use GitHub Actions instead
Workers Builds is all most projects need. Use GitHub Actions if you want deploys to run inside your own pipeline, for example only after tests and type checks pass. Pick one or the other: if you leave Workers Builds connected as well, every push deploys twice.
Create an API token at dash.cloudflare.com/profile/api-tokens using the Edit Cloudflare Workers template. In your GitHub repo, open Settings → Secrets and variables → Actions and add:
CLOUDFLARE_API_TOKEN: the token you just createdCLOUDFLARE_ACCOUNT_ID: your account ID- Every
NEXT_PUBLIC_*value your build needs. Add these as Variables, since they end up public anyway.
Then add .github/workflows/deploy.yml:
name: Deploy on: push: branches: [main] pull_request: jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: 22 cache: npm - run: npm ci - name: Deploy to production if: github.ref == 'refs/heads/main' run: npx @vinext/cloudflare deploy env: CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} NEXT_PUBLIC_API_URL: ${{ vars.NEXT_PUBLIC_API_URL }} - name: Deploy pull request preview if: github.event_name == 'pull_request' run: npx @vinext/cloudflare previews deploy pr-${{ github.event.number }} env: CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} NEXT_PUBLIC_API_URL: ${{ vars.NEXT_PUBLIC_API_URL }}
Pushes to main now go to production. Each pull request gets a Worker Preview: a separate URL running the PR's code next to your live Worker, without touching production traffic. Previews build in production mode by default. Add --mode preview to load .env.preview instead.
Warning: Whichever setup you use, don't use
deploy --previewfor pull requests. Despite the name,--previewonly selects thepreviewmode, the same as--env preview, and still deploys to your live Worker, so every PR would replace production. Always usepreviews deploy.
If you use the Response Store in its default two-Worker mode, Workers Builds and this workflow both redeploy only the app. Run npm run deploy:response-store yourself, after a build, whenever you upgrade @cloudflare/workers-response-store or change its config.

Make vinext the default
Once everything works in production, point your main scripts at vinext and remove the :vinext copies:
"scripts": { "dev": "vite dev", "build": "vite build", "start": "vite preview", "deploy": "vinext-cloudflare deploy" }
For a Cloudflare project, start stays vite preview, because that runs the build in workerd. vinext start is the plain Node.js server, which you'd only use for a Node deployment.
vinext includes its own types for the next/* APIs it supports, so you can remove the next package if nothing else depends on it. Keep it if you use features that rely on Next.js internals, such as styled-jsx.
Not on Cloudflare? Use Nitro
vinext can also deploy to other platforms through the Nitro Vite plugin. You keep the core Next.js API, but the Cloudflare-specific parts of this guide come from @vinext/cloudflare and don't carry over: the one-command deploy, the Images optimiser, the Response Store and KV cache adapters, Worker Previews and Workers Builds. You'll need to replace each of them with your platform's own tools.
npm install nitro
// vite.config.ts import { defineConfig } from "vite"; import vinext from "vinext"; import { nitro } from "nitro/vite"; export default defineConfig({ plugins: [vinext(), nitro()], });
Nitro detects most CI platforms automatically. To build for a specific platform locally, set the preset, for example NITRO_PRESET=vercel npx vite build (or netlify, aws_amplify, deno_deploy or node). If you want a single Node server for Docker or a VPS, set output: "standalone" in next.config instead and run node dist/standalone/server.js.
Known limitations (as of vinext 1.4)
- Partial Prerendering and full
cacheComponentsaren't supported yet. - Images aren't optimised at build time. Optimisation happens at request time through Cloudflare Images instead.
next/font/localCSS is injected at runtime rather than extracted during the build. - Pre-rendered routes (
prerender: { routes: "*" }) are built but not served by a Cloudflare deploy unless you use the Static Assets cache. preferredRegionis ignored, and theruntimeexport doesn't change where code runs.- Native Node addons can't run on Workers.
- Vercel-specific services, AMP and the legacy
next exportare intentionally not supported.
Check the vinext repo for the current list. The project moves quickly.
Quick checklist
- Node 22.23+ (or 24.22+) in use locally and in CI
-
npx vinext checkpasses, or every issue has a workaround - Any old
wrangler.*config migrated intocloudflare.config.ts -
npx vinext init --platform=cloudflarerun, and changes committed -
.cloudflare/typesintsconfig.json, anddist/,.vinext/and.cloudflare/gitignored - App tested on
localhost:3001, with key flows clicked through - Production build tested locally with
start:vinextonlocalhost:4173 - Logged in with
npx cf auth login, and account ID set - Response Store Worker deployed first, if you chose it
- First
npm run deploy:vinextsucceeded -
NEXT_PUBLIC_*values present at build time - Every server-only variable set on the Worker (
bindings.text()or a secret), not just in.env - Shared cache (Response Store or KV) set up if you use ISR or
"use cache" - Custom domain attached
- Workers Builds connected, deploying
mainand runningpreviews deployfor other branches (or GitHub Actions, if you prefer)
Wrap up
You kept the Next.js code you already know, app/ directory, Server Components, Server Actions and all, and swapped the build toolchain underneath it for Vite. On Workers, the platform vinext was built for, the result runs on Cloudflare's global network, close to every visitor. It has bindings to a database, storage and a shared cache, and it redeploys itself every time you push.
Start with npx vinext check on a side project this week. It takes a minute, changes nothing and shows you how close you already are.
Found this useful? Share it with the friend who still says Next.js only really works on Vercel.





