Skip to main content
Deploys your Next.js application to Cloudflare Workers with automatic configuration generation. Handles App Router and Pages Router projects with zero config required.

Usage

Options

flag
Deploy to a preview environment instead of production.
Creates a temporary preview URL for testing before production deployment.
string
Custom Worker name. Defaults to project name from package.json.
Worker names must be lowercase alphanumeric with hyphens.
flag
Skip the build step and deploy existing dist/ output.
Useful when you’ve already built and want to deploy quickly.
flag
Generate config files without building or deploying.
Shows what files would be created: wrangler.jsonc, worker/index.ts, vite.config.ts.
flag
Show help for this command. Can also use -h.

Experimental: Traffic-aware Pre-Rendering (TPR)

TPR is experimental and must be explicitly enabled. Requires a custom domain (zone analytics unavailable on *.workers.dev) and CLOUDFLARE_API_TOKEN with Zone.Analytics read permission.
flag
Enable Traffic-aware Pre-Rendering using Cloudflare zone analytics.
Pre-renders hot pages into KV cache during deployment based on actual traffic data.
number
default:"90"
Traffic coverage target percentage (0-100).
Pre-renders enough pages to cover 95% of actual traffic.
number
default:"1000"
Hard cap on number of pages to pre-render.
Prevents excessive KV usage on high-traffic sites.
number
default:"24"
Analytics lookback window in hours.
Uses the last 48 hours of traffic data to determine hot pages.

What It Does

The deploy command automates the entire Cloudflare Workers deployment:

1. Project Detection

Scans your project to determine:
  • Router type: App Router vs Pages Router
  • ISR usage: Detects export const revalidate in pages
  • MDX usage: Checks for .mdx files or @next/mdx config
  • Native modules: Detects modules that need stubbing (@resvg/resvg-js, satori, etc.)
  • Existing config: Checks for wrangler.jsonc, worker/index.ts, vite.config.ts

2. Dependency Installation

Automatically installs required packages if missing:
  • @cloudflare/vite-plugin (always required)
  • wrangler (Cloudflare Workers CLI)
  • @vitejs/plugin-rsc (App Router only)
  • @mdx-js/rollup (if MDX detected)

3. ESM Configuration

Cloudflare Workers requires ESM. vinext automatically:
  1. Renames CJS config files:
    • next.config.jsnext.config.cjs
    • postcss.config.jspostcss.config.cjs
  2. Adds "type": "module" to package.json

4. Config File Generation

Generates missing files:
Cloudflare Workers configuration:
If ISR is detected, adds KV namespace:
Worker entry for App Router with image optimization:
Worker entry for Pages Router:
Vite configuration with Cloudflare plugin:
If native modules are detected, adds stub aliases:

5. Build for Workers

Runs the Vite build with Cloudflare-specific configuration:
The @cloudflare/vite-plugin handles Worker-specific bundling.

6. Deploy via Wrangler

Executes wrangler deploy to publish to Cloudflare:

Examples

First Deployment

Deploy to production:
Output:

Preview Deployment

Deploy to preview environment for testing:
Creates a temporary preview URL: https://my-app-preview.example.workers.dev

Custom Worker Name

Deploy with a custom name:

Dry Run (See What Would Be Generated)

Output:

Skip Build (Deploy Existing Build)

Useful for quick redeployment:

Traffic-aware Pre-Rendering

Pre-render hot pages based on analytics:
With custom coverage target:

ISR (Incremental Static Regeneration)

If your app uses ISR, vinext automatically:
  1. Detects export const revalidate in pages
  2. Adds KV namespace binding to wrangler.jsonc
  3. Configures runtime cache handler
After deployment, you need to create the KV namespace:
Update wrangler.jsonc:
Redeploy:

Custom Domains

To use a custom domain:
  1. Add your domain in Cloudflare dashboard
  2. Add route to wrangler.jsonc:
  1. Deploy:

Environment Variables

Set secrets using wrangler:
Or bulk upload from .env.production:
Access in your app:

CI/CD Integration

GitHub Actions

GitLab CI

Troubleshooting

”No wrangler found”

vinext installs wrangler automatically, but if you see this error:

“Invalid Worker name”

Worker names must be lowercase alphanumeric with hyphens:

Build Fails with Native Module Error

Some native Node.js modules don’t work in Workers. vinext automatically stubs common ones:
  • @resvg/resvg-js
  • satori
  • lightningcss
  • @napi-rs/canvas
  • sharp
If you need a stubbed module, create empty-stub.js:

Deploy Fails with “Unauthorized”

Set your Cloudflare API token:
Get a token from: https://dash.cloudflare.com/profile/api-tokens Required permissions:
  • Account.Workers Scripts (Edit)
  • Account.Workers KV Storage (Edit, if using ISR)

Pricing

Cloudflare Workers Free tier:
  • 100,000 requests/day
  • 10ms CPU time per request
  • Unlimited bandwidth
  • Unlimited storage (KV: 1GB free)
Paid tier ($5/month):
  • 10 million requests/month (included)
  • 50ms CPU time per request
  • $0.50 per million requests after
  • KV: 10GB included
Most Next.js apps stay within the free tier during development and small-scale production use.

Next Steps

Cloudflare Deployment

Deep dive into Cloudflare Workers deployment

check Command

Check your project for compatibility