Build and Preview Commands
apps/site/package.json:
Configuration Files
Two files control the Cloudflare deployment:wrangler.jsonc
Cloudflare Worker settings: account ID, R2 buckets, Durable Objects, build command, module aliases.
open-next.config.ts
OpenNext Cloudflare adapter configuration. Controls how Next.js output is adapted for Cloudflare Workers.
Wrangler Configuration
Thewrangler.jsonc file defines the Cloudflare Worker. Key settings:
main
Points to the Worker entry file generated by the OpenNext adapter during the build.
account_id
The Cloudflare account ID. Not required for local preview (wrangler dev), but required for deployment. Currently set to the Node.js testing account (fb4a2d0f103c6ff38854ac69eb709272).
build
Defines the build command that generates Node.js filesystem polyfills required for the application to run on Cloudflare Workers. Uses the @flarelabs/wrangler-build-time-fs-assets-polyfilling package.
alias
Maps module aliases for the Node.js filesystem polyfills generated at build time.
r2_buckets
Defines R2 bucket bindings. The site uses one R2 bucket:
NEXT_INC_CACHE_R2_BUCKET implements the Next.js incremental cache, replacing the file-system cache that would be used in a Node.js environment.
durable_objects
Defines Durable Object bindings:
NEXT_CACHE_DO_QUEUE implements the OpenNext cache queue, coordinating cache invalidation across Workers.
OpenNext Configuration
Theopen-next.config.ts file configures the OpenNext Cloudflare adapter. It tells the adapter how to adapt the Next.js build output to run as a Cloudflare Worker.
The OPEN_NEXT_CLOUDFLARE environment variable signals to next.config.mjs that a Cloudflare build is in progress, enabling Cloudflare-specific configuration (such as the custom image loader).
Skew Protection
Vercel provides version skew protection out of the box. Cloudflare does not — the OpenNext adapter provides its own implementation. OpenNext skew protection requires three environment variables inwrangler.jsonc:
| Variable | Description |
|---|---|
CF_WORKER_NAME | Name of the Worker (same as the name field in wrangler.jsonc) |
CF_ACCOUNT_ID | Cloudflare account ID (same as account_id) |
CF_PREVIEW_DOMAIN | Preview domain for the Worker. For Node.js this is nodejsorg |
| Variable | Description |
|---|---|
CF_WORKERS_SCRIPTS_API_TOKEN | API token with Workers Scripts:Read permission |
Custom Image Loader
When deployed on Cloudflare, Next.js’s default image optimization pipeline is not available. A custom image loader is required. The loader is atapps/site/cloudflare/image-loader.ts and is activated in next.config.mjs when the OPEN_NEXT_CLOUDFLARE environment variable is set:
Deployment ID (Skew Protection Mechanism)
The Cloudflare adapter requires adeploymentId to be set in the Next.js config for skew protection to work:
Differences from Vercel Deployment
| Feature | Vercel | Cloudflare |
|---|---|---|
| Skew protection | Built-in | Requires OpenNext implementation + env vars |
| Image optimization | Next.js built-in | Custom Cloudflare Images loader |
| Incremental cache | File system / Vercel KV | R2 bucket (NEXT_INC_CACHE_R2_BUCKET) |
| Cache coordination | Vercel | Durable Objects (NEXT_CACHE_DO_QUEUE) |
| Install command | pnpm install --prod | opennextjs-cloudflare build |
| Output | .next/ | Cloudflare Worker bundle |