jackspace/claudeskillz/cloudflare-nextjs
- community
Checking that the SKILL.md file is still in the repository.
Covers deploying Next.js apps (App Router and Pages Router) to Cloudflare Workers with the OpenNext adapter @opennextjs/cloudflare: scaffolding new projects via create-cloudflare, migrating existing apps, wrangler.jsonc and open-next.config.ts setup, the nodejs_compat flag and compatibility_date, the dual next dev plus opennextjs-cloudflare preview workflow, deployment, image optimization, caching, and bindings for D1, R2, KV and Workers AI. Use when running SSR, ISR, server components, server actions or middleware on Workers, moving a Next.js app from Vercel or AWS to Cloudflare, or hitting errors such as worker size limit exceeded (3 MiB free, 10 MiB paid), FinalizationRegistry is not defined, Cannot perform I/O on behalf of a different request, Turbopack chunk load failures, request-scoped database connection problems, or the CVE-2025-6087 SSRF vulnerability.
Install
npx vskill@latest install jackspace/claudeskillz/cloudflare-nextjsSKILL.md
Cloudflare Next.js Deployment Skill
Deploy Next.js applications to Cloudflare Workers using the OpenNext Cloudflare adapter for production-ready serverless Next.js hosting.
Use This Skill When
- Deploying Next.js applications (App Router or Pages Router) to Cloudflare Workers
- Need server-side rendering (SSR), static site generation (SSG), or incremental static regeneration (ISR) on Cloudflare
- Migrating existing Next.js apps from Vercel, AWS, or other platforms to Cloudflare
- Building full-stack Next.js applications with Cloudflare services (D1, R2, KV, Workers AI)
- Need React Server Components, Server Actions, or Next.js middleware on Workers
- Want global edge deployment with Cloudflare's network
Key Concepts
OpenNext Adapter Architecture
The OpenNext Cloudflare adapter (@opennextjs/cloudflare) transforms Next.js build output into Cloudflare Worker-compatible format. This is fundamentally different from standard Next.js deployments:
- Node.js Runtime Required: Uses Node.js runtime in Workers (NOT Edge runtime)
- Dual Development Workflow: Test in both Next.js dev server AND workerd runtime
- Custom Build Pipeline:
next build→ OpenNext transformation → Worker deployment - Cloudflare-Specific Configuration: Requires wrangler.jsonc and open-next.config.ts
Critical Differences from Standard Next.js
| Aspect | Standard Next.js | Cloudflare Workers | |
|---|---|---|---|
| Runtime | Node.js or Edge | Node.js (via nodejs_compat) | |
| Dev Server | next dev | next dev + opennextjs-cloudflare preview | |
| Deployment | Platform-specific | opennextjs-cloudflare deploy | |
| Worker Size | No limit | 3 MiB (free) / 10 MiB (paid) | |
| Database Connections | Global clients OK | Must be request-scoped | |
| Image Optimization | Built-in | Via Cloudflare Images | |
| Caching | Next.js cache | OpenNext config + Workers cache |
Setup Patterns
New Project Setup
Use Cloudflare's create-cloudflare (C3) CLI to scaffold a new Next.js project pre-configured for Workers:
What this does:
- Runs Next.js official setup tool (
create-next-app) - Installs
@opennextjs/cloudflareadapter - Creates
wrangler.jsoncwith correct configuration - Creates
open-next.config.tsfor caching configuration - Adds deployment scripts to
package.json - Optionally deploys immediately to Cloudflare
Development workflow:
Existing Project Migration
To add the OpenNext adapter to an existing Next.js application:
1. Install the adapter
2. Create wrangler.jsonc
Critical configuration:
compatibility_date: Minimum `2025-05-05` (for FinalizationRegistry support)compatibility_flags: Must include `nodejs_compat` (for Node.js runtime)
3. Create open-next.config.ts
4. Update package.json scripts
Script purposes:
dev: Next.js development server (fast iteration)preview: Build + run in workerd runtime (test before deploy)deploy: Build + deploy to Cloudflarecf-typegen: Generate TypeScript types for Cloudflare bindings
5. Ensure Node.js runtime (not Edge)
Remove Edge runtime exports from your app:
Development Workflow
Dual Testing Strategy
Always test in BOTH environments:
- Next.js Dev Server (
npm run dev)
- Fast hot reloading
- Best developer experience
- Runs in Node.js (not production runtime)
- Use for rapid iteration
- Workerd Runtime (
npm run preview)
- Runs in production-like environment
- Catches runtime-specific issues
- Slower rebuild times
- Required before deployment
When to Use Each
Configuration Requirements
Wrangler Configuration
Minimum requirements in wrangler.jsonc:
Environment Variables for Package Exports
If using npm packages with multiple export conditions, create .env:
This ensures Wrangler prioritizes the node export when available.
Cloudflare Bindings Integration
Add bindings in wrangler.jsonc:
Access bindings in Next.js via process.env:
Error Prevention (10+ Documented Errors)
1. Worker Size Limit Exceeded (3 MiB - Free Plan)
Error: "Your Worker exceeded the size limit of 3 MiB"
Cause: Workers Free plan limits Worker size to 3 MiB (gzip-compressed)
Solutions:
- Upgrade to Workers Paid plan (10 MiB limit)
- Analyze bundle size and remove unused dependencies
- Use dynamic imports to code-split large dependencies
Bundle analysis:
Source: https://opennext.js.org/cloudflare/troubleshooting#worker-size-limits
2. Worker Size Limit Exceeded (10 MiB - Paid Plan)
Error: "Your Worker exceeded the size limit of 10 MiB"
Cause: Unnecessary code bundled into Worker
Debug workflow:
- Run
npx opennextjs-cloudflare build - Navigate to
.open-next/server-functions/default - Analyze
handler.mjs.meta.jsonusing ESBuild Bundle Analyzer - Identify and remove/externalize large dependencies
Source: https://opennext.js.org/cloudflare/troubleshooting#worker-size-limits
3. FinalizationRegistry Not Defined
Error: "ReferenceError: FinalizationRegistry is not defined"
Cause: compatibility_date in wrangler.jsonc is too old
Solution: Update compatibility_date to 2025-05-05 or later:
Source: https://opennext.js.org/cloudflare/troubleshooting#finalizationregistry-is-not-defined
4. Cannot Perform I/O on Behalf of Different Request
Error: "Cannot perform I/O on behalf of a different request"
Cause: Database client created globally and reused across requests
Problem code:
Solution: Create database clients inside request handlers:
Alternative: Use Cloudflare D1 (designed for Workers) instead of external databases:
Source: https://opennext.js.org/cloudflare/troubleshooting#cannot-perform-io-on-behalf-of-a-different-request
5. NPM Package Import Failures
Error: "Could not resolve '<package>'"
Cause: Missing nodejs_compat flag or package export conditions
Solution 1: Enable nodejs_compat flag:
Solution 2: For packages with multiple exports, create .env:
Source: https://opennext.js.org/cloudflare/troubleshooting#npm-packages-fail-to-import
6. Failed to Load Chunk (Turbopack)
Error: "Failed to load chunk server/chunks/ssr/"
Cause: Next.js built with Turbopack (next build --turbo)
Solution: Use standard build (Turbopack not supported by adapter):
Source: https://opennext.js.org/cloudflare/troubleshooting#failed-to-load-chunk
7. SSRF Vulnerability (CVE-2025-6087)
Vulnerability: Server-Side Request Forgery via /_next/image endpoint
Affected versions: @opennextjs/cloudflare < 1.3.0
Solution: Upgrade to version 1.3.0 or later:
Impact: Allows unauthenticated users to proxy arbitrary remote content
Source: https://github.com/advisories/GHSA-rvpw-p7vw-wj3m
8. Durable Objects Binding Warnings
Warning: "You have defined bindings to the following internal Durable Objects... will not work in local development, but they should work in production"
Cause: OpenNext uses Durable Objects for caching (DOQueueHandler, DOShardedTagCache)
Solution: Safe to ignore - warning is expected behavior
Alternative (to suppress warning): Define Durable Objects in separate Worker with own config
Source: https://opennext.js.org/cloudflare/known-issues#caching-durable-objects
9. Prisma + D1 Middleware Conflicts
Error: Build errors when using @prisma/client + @prisma/adapter-d1 in Next.js middleware
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/cloudflare-nextjs/SKILL.md
Popularity
- Repository stars
- 14
- Repository forks
- 6
- 7-day trend score
- 14
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 2 May 2026, 5 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/jackspace/claudeskillz/cloudflare-nextjs)