Token导航 LogoToken导航

Agent Skill · 前端设计

cloudflare-nextjs(Cloudflare Next.js 前端)

用于辅助前端页面、组件、样式和交互逻辑的开发与维护。它适合让 Agent 生成或审查 React、Next.js、Vue、Tailwind、CSS 等相关代码,整理组件结构,或定位布局和性能问题。使用时需要结合项目现有设计系统、路由和构建方式,避免只生成孤立片段;涉及页面改动时,应配合本地预览和构建检查确认视觉效果。

cloudflare-nextjs 是前端设计类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为接触敏感数据;许可证为 MIT,第三方扫描有提醒项,按安装量在前端设计类的 10,216 个 Skill 里排第 2,519。

总安装 2,182周安装 90GitHub Stars 14下载 713核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
MIT

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:cloudflare-nextjs(Cloudflare Next.js 前端)
来源仓库:https://github.com/jackspace/claudeskillz
仓库路径:skills/cloudflare-nextjs
安装命令:
npx skills add https://github.com/jackspace/claudeskillz --skill cloudflare-nextjs
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/jackspace/claudeskillz --skill cloudflare-nextjs

这个 Skill 是做什么的

前端设计类 Skill 关注页面结构、视觉规范和组件写法,输出通常是可运行的界面代码。

将 Next.js 应用部署至 Cloudflare Workers,支持 SSR、SSG 和 ISR。利用 OpenNext 适配器实现 React Server Components 与 Cloudflare 绑定。可集成 D1、R2、KV 等服务构建全栈应用,迁移自 Vercel 或其他平台。

需配置 wrangler.jsonc 并选择适配框架(App Router 或 Pages Router)。部署后建议验证静态资源路径与动态请求的路由映射正确性。

来源仓库内路径:skills/cloudflare-nextjs

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/jackspace/claudeskillz --skill cloudflare-next…;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它需要接触敏感数据,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

cloudflare-nextjs 怎么安装?

在终端执行 npx skills add https://github.com/jackspace/claudeskillz --skill cloudflare-nextjs。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

cloudflare-nextjs 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

cloudflare-nextjs 需要什么权限?

权限级别是接触敏感数据。该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

cloudflare-nextjs 是免费的吗?

来源标注的许可证是 MIT。本站不代收任何费用,也不托管安装包;能否商用、要不要署名,以许可证原文为准。

cloudflare-nextjs 用的人多吗?

公开数据是累计安装 2,182 次,近一周安装 90 次,下载 713 次,GitHub 14 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

cloudflare-nextjs 安全吗?

第三方扫描有提醒项,说明存在需要人工确认的行为。安装前请打开源码看清它读了什么、联网到哪里。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 3 个目录同时收录,说明这个 Skill 流传比较广。
  • 许可证明确为 MIT,商用和分发边界好判断。

先想清楚的地方

  • 需要接触敏感数据,装到常用环境前要先评估影响面。
  • 第三方扫描存在提醒项或未通过项,需要人工逐条确认。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理前端设计类任务、又不想每次都手写提示词的人。

不太适合

  • 环境里有大量密钥、凭证,不方便给第三方 Skill 读取的人。
  • 需要厂商级技术支持和 SLA 的生产系统。

前端设计类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
frontend-design

前端设计 · Codex、Claude

8,823,360126,072只读MIT通过
vercel-composition-patterns

Vercel 组合模式 · Codex、Claude

3,858,81625,893需要联网MIT通过
vercel-react-native-skills

Vercel React native skills 前端 · Codex、Claude

2,468,66425,878只读MIT通过
adapt

adapt 搜索 · Codex、Claude

2,027,04023,125操作浏览器未明确通过
bolder

bolder 分析 · Codex、Claude

2,004,28823,130只读未明确通过
cloudflare-nextjs

Cloudflare Next.js 前端 · 本页

2,18214接触敏感数据MIT有提醒

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.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

AspectStandard Next.jsCloudflare Workers
RuntimeNode.js or EdgeNode.js (via nodejs_compat)
Dev Servernext devnext dev + opennextjs-cloudflare preview
DeploymentPlatform-specificopennextjs-cloudflare deploy
Worker SizeNo limit3 MiB (free) / 10 MiB (paid)
Database ConnectionsGlobal clients OKMust be request-scoped
Image OptimizationBuilt-inVia Cloudflare Images
CachingNext.js cacheOpenNext 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:

npm create cloudflare@latest -- my-next-app --framework=next

What this does:

  1. Runs Next.js official setup tool (create-next-app)
  2. Installs @opennextjs/cloudflare adapter
  3. Creates wrangler.jsonc with correct configuration
  4. Creates open-next.config.ts for caching configuration
  5. Adds deployment scripts to package.json
  6. Optionally deploys immediately to Cloudflare

Development workflow:

npm run dev      # Next.js dev server (fast reloads)
npm run preview  # Test in workerd runtime (production-like)
npm run deploy   # Build and deploy to Cloudflare

Existing Project Migration

To add the OpenNext adapter to an existing Next.js application:

1. Install the adapter
npm install --save-dev @opennextjs/cloudflare
2. Create wrangler.jsonc
{
  "name": "my-next-app",
  "compatibility_date": "2025-05-05",
  "compatibility_flags": ["nodejs_compat"]
}

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
import { defineCloudflareConfig } from "@opennextjs/cloudflare";

export default defineCloudflareConfig({
  // Caching configuration (optional)
  // See: https://opennext.js.org/cloudflare/caching
});
4. Update package.json scripts
{
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "preview": "opennextjs-cloudflare build && opennextjs-cloudflare preview",
    "deploy": "opennextjs-cloudflare build && opennextjs-cloudflare deploy",
    "cf-typegen": "wrangler types --env-interface CloudflareEnv cloudflare-env.d.ts"
  }
}

Script purposes:

  • dev: Next.js development server (fast iteration)
  • preview: Build + run in workerd runtime (test before deploy)
  • deploy: Build + deploy to Cloudflare
  • cf-typegen: Generate TypeScript types for Cloudflare bindings
5. Ensure Node.js runtime (not Edge)

Remove Edge runtime exports from your app:

// ❌ REMOVE THIS (Edge runtime not supported)
export const runtime = "edge";

// ✅ Use Node.js runtime (default)
// No export needed - Node.js is default

Development Workflow

Dual Testing Strategy

Always test in BOTH environments:

  1. Next.js Dev Server (npm run dev)

- Fast hot reloading - Best developer experience - Runs in Node.js (not production runtime) - Use for rapid iteration

  1. Workerd Runtime (npm run preview)

- Runs in production-like environment - Catches runtime-specific issues - Slower rebuild times - Required before deployment

When to Use Each

# Iterating on UI/logic → Use Next.js dev server
npm run dev

# Testing integrations (D1, R2, KV) → Use preview
npm run preview

# Before deploying → ALWAYS test preview
npm run preview

# Deploy to production
npm run deploy

Configuration Requirements

Wrangler Configuration

Minimum requirements in wrangler.jsonc:

{
  "name": "your-app-name",
  "compatibility_date": "2025-05-05",  // Minimum for FinalizationRegistry
  "compatibility_flags": ["nodejs_compat"]  // Required for Node.js runtime
}

Environment Variables for Package Exports

If using npm packages with multiple export conditions, create .env:

WRANGLER_BUILD_CONDITIONS=""
WRANGLER_BUILD_PLATFORM="node"

This ensures Wrangler prioritizes the node export when available.

Cloudflare Bindings Integration

Add bindings in wrangler.jsonc:

{
  "name": "your-app-name",
  "compatibility_date": "2025-05-05",
  "compatibility_flags": ["nodejs_compat"],

  // D1 Database
  "d1_databases": [
    {
      "binding": "DB",
      "database_name": "production-db",
      "database_id": "your-database-id"
    }
  ],

  // R2 Storage
  "r2_buckets": [
    {
      "binding": "BUCKET",
      "bucket_name": "your-bucket"
    }
  ],

  // KV Storage
  "kv_namespaces": [
    {
      "binding": "KV",
      "id": "your-kv-id"
    }
  ],

  // Workers AI
  "ai": {
    "binding": "AI"
  }
}

Access bindings in Next.js via process.env:

// app/api/route.ts
import type { NextRequest } from 'next/server';

export async function GET(request: NextRequest) {
  // Access Cloudflare bindings
  const env = process.env as any;

  // D1 Database query
  const result = await env.DB.prepare('SELECT * FROM users').all();

  // R2 Storage access
  const file = await env.BUCKET.get('file.txt');

  // KV Storage access
  const value = await env.KV.get('key');

  // Workers AI inference
  const response = await env.AI.run('@cf/meta/llama-3-8b-instruct', {
    prompt: 'Hello AI'
  });

  return Response.json({ result });
}

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:

npx opennextjs-cloudflare build
cd .open-next/server-functions/default
# Analyze handler.mjs.meta.json with ESBuild Bundle Analyzer

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:

  1. Run npx opennextjs-cloudflare build
  2. Navigate to .open-next/server-functions/default
  3. Analyze handler.mjs.meta.json using ESBuild Bundle Analyzer
  4. 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:

{
  "compatibility_date": "2025-05-05"  // Minimum for FinalizationRegistry
}

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:

// ❌ WRONG: Global DB client
import { Pool } from 'pg';
const pool = new Pool({ connectionString: process.env.DATABASE_URL });

export async function GET() {
  // This will fail - pool created in different request context
  const result = await pool.query('SELECT * FROM users');
  return Response.json(result);
}

Solution: Create database clients inside request handlers:

// ✅ CORRECT: Request-scoped DB client
import { Pool } from 'pg';

export async function GET() {
  // Create client within request context
  const pool = new Pool({ connectionString: process.env.DATABASE_URL });
  const result = await pool.query('SELECT * FROM users');
  await pool.end();
  return Response.json(result);
}

Alternative: Use Cloudflare D1 (designed for Workers) instead of external databases:

// ✅ BEST: Use D1 (no connection pooling needed)
export async function GET(request: NextRequest) {
  const env = process.env as any;
  const result = await env.DB.prepare('SELECT * FROM users').all();
  return Response.json(result);
}

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:

{
  "compatibility_flags": ["nodejs_compat"]
}

Solution 2: For packages with multiple exports, create .env:

WRANGLER_BUILD_CONDITIONS=""
WRANGLER_BUILD_PLATFORM="node"

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):

{
  "scripts": {
    "build": "next build"  // ✅ Correct
    // "build": "next build --turbo"  // ❌ Don't use Turbopack
  }
}

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:

npm install --save-dev @opennextjs/cloudflare@^1.3.0

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

Cause: Database initialization in middleware context

Workaround: Initialize Prisma client in route handlers, not middleware

Source: https://github.com/opennextjs/opennextjs-cloudflare/issues/471


10. cross-fetch Library Errors

Error: Errors when using libraries that depend on cross-fetch

Cause: OpenNext patches deployment package causing cross-fetch to try using Node.js libraries when native fetch is available

Solution: Use native fetch API directly instead of cross-fetch:

// ✅ Use native fetch
const response = await fetch('https://api.example.com/data');

// ❌ Avoid cross-fetch
// import fetch from 'cross-fetch';

Source: https://opennext.js.org/cloudflare/troubleshooting


11. Windows Development Issues

Issue: Full Windows support not guaranteed

Cause: Underlying Next.js tooling issues on Windows

Solutions:

  • Use WSL (Windows Subsystem for Linux)
  • Use virtual machine with Linux
  • Use Linux-based CI/CD for deployments

Source: https://opennext.js.org/cloudflare#windows-support

Feature Support Matrix

FeatureStatusNotes
App Router✅ Fully SupportedLatest App Router features work
Pages Router✅ Fully SupportedLegacy Pages Router supported
Route Handlers✅ Fully SupportedAPI routes work as expected
React Server Components✅ Fully SupportedRSC fully functional
Server Actions✅ Fully SupportedServer Actions work
SSG✅ Fully SupportedStatic Site Generation
SSR✅ Fully SupportedServer-Side Rendering
ISR✅ Fully SupportedIncremental Static Regeneration
Middleware✅ SupportedExcept Node.js middleware (15.2+)
Image Optimization✅ SupportedVia Cloudflare Images
Partial Prerendering (PPR)✅ SupportedExperimental in Next.js
Composable Caching✅ Supported'use cache' directive
Response Streaming✅ SupportedStreaming responses work
next/after API✅ SupportedPost-response async work
Node.js Middleware (15.2+)❌ Not SupportedFuture support planned
Edge Runtime❌ Not SupportedUse Node.js runtime

Source: https://developers.cloudflare.com/workers/framework-guides/web-apps/nextjs/#next-js-supported-features

Integration with Cloudflare Services

D1 Database (SQL)

// app/api/users/route.ts
import type { NextRequest } from 'next/server';

export async function GET(request: NextRequest) {
  const env = process.env as any;

  const result = await env.DB.prepare(
    'SELECT * FROM users WHERE active = ?'
  ).bind(true).all();

  return Response.json(result.results);
}

export async function POST(request: NextRequest) {
  const env = process.env as any;
  const { name, email } = await request.json();

  const result = await env.DB.prepare(
    'INSERT INTO users (name, email) VALUES (?, ?)'
  ).bind(name, email).run();

  return Response.json({ id: result.meta.last_row_id });
}

Wrangler config:

{
  "d1_databases": [
    {
      "binding": "DB",
      "database_name": "production-db",
      "database_id": "your-database-id"
    }
  ]
}

See also: cloudflare-d1 skill for complete D1 patterns


R2 Storage (Object Storage)

// app/api/upload/route.ts
import type { NextRequest } from 'next/server';

export async function POST(request: NextRequest) {
  const env = process.env as any;
  const formData = await request.formData();
  const file = formData.get('file') as File;

  // Upload to R2
  await env.BUCKET.put(file.name, file.stream(), {
    httpMetadata: {
      contentType: file.type
    }
  });

  return Response.json({ success: true, filename: file.name });
}

export async function GET(request: NextRequest) {
  const env = process.env as any;
  const { searchParams } = new URL(request.url);
  const filename = searchParams.get('file');

  const object = await env.BUCKET.get(filename);
  if (!object) {
    return new Response('Not found', { status: 404 });
  }

  return new Response(object.body, {
    headers: {
      'Content-Type': object.httpMetadata?.contentType || 'application/octet-stream'
    }
  });
}

See also: cloudflare-r2 skill for complete R2 patterns


Workers AI (Model Inference)

// app/api/ai/route.ts
import type { NextRequest } from 'next/server';

export async function POST(request: NextRequest) {
  const env = process.env as any;
  const { prompt } = await request.json();

  const response = await env.AI.run('@cf/meta/llama-3-8b-instruct', {
    prompt
  });

  return Response.json(response);
}

Wrangler config:

{
  "ai": {
    "binding": "AI"
  }
}

See also: cloudflare-workers-ai skill for complete AI patterns


KV Storage (Key-Value)

// app/api/cache/route.ts
import type { NextRequest } from 'next/server';

export async function GET(request: NextRequest) {
  const env = process.env as any;
  const { searchParams } = new URL(request.url);
  const key = searchParams.get('key');

  const value = await env.KV.get(key);
  return Response.json({ key, value });
}

export async function PUT(request: NextRequest) {
  const env = process.env as any;
  const { key, value, ttl } = await request.json();

  await env.KV.put(key, value, { expirationTtl: ttl });
  return Response.json({ success: true });
}

See also: cloudflare-kv skill for complete KV patterns

Image Optimization

Next.js image optimization works via Cloudflare Images. Configure in open-next.config.ts:

import { defineCloudflareConfig } from "@opennextjs/cloudflare";

export default defineCloudflareConfig({
  imageOptimization: {
    loader: 'cloudflare'
  }
});

Usage in components:

import Image from 'next/image';

export default function Avatar() {
  return (
    <Image
      src="/avatar.jpg"
      alt="User avatar"
      width={200}
      height={200}
      // Automatically optimized via Cloudflare Images
    />
  );
}

Billing: Cloudflare Images usage is billed separately

Docs: https://developers.cloudflare.com/images/

Caching Configuration

Configure caching behavior in open-next.config.ts:

import { defineCloudflareConfig } from "@opennextjs/cloudflare";

export default defineCloudflareConfig({
  // Custom cache configuration
  cache: {
    // Override default cache behavior
    // See: https://opennext.js.org/cloudflare/caching
  }
});

Default behavior: OpenNext provides sensible caching defaults

Advanced usage: See official OpenNext caching documentation

Known Limitations

Not Yet Supported

  1. Node.js Middleware (Next.js 15.2+)

- Introduced in Next.js 15.2 - Support planned for future releases - Use standard middleware for now

  1. Edge Runtime

- Only Node.js runtime supported - Remove export const runtime = "edge" from your app

  1. Full Windows Support

- Development on Windows not fully guaranteed - Use WSL, VM, or Linux-based CI/CD

Worker Size Constraints

  • Free plan: 3 MiB limit (gzip-compressed)
  • Paid plan: 10 MiB limit (gzip-compressed)
  • Monitor bundle size during development
  • Use dynamic imports for code splitting

Database Connections

  • External database clients (PostgreSQL, MySQL) must be request-scoped
  • Cannot reuse connections across requests (Workers limitation)
  • Prefer Cloudflare D1 for database needs (designed for Workers)

Deployment

Deploy from Local Machine

# Build and deploy in one command
npm run deploy

# Or step by step:
npx opennextjs-cloudflare build
npx opennextjs-cloudflare deploy

Deploy from CI/CD

Configure deployment command in your CI/CD system:

npm run deploy

Examples:

  • GitHub Actions: .github/workflows/deploy.yml
  • GitLab CI: .gitlab-ci.yml
  • Cloudflare Workers Builds: Auto-detects npm run deploy

Environment variables: Set secrets in Cloudflare dashboard or CI/CD system

Custom Domains

Add custom domain in Cloudflare dashboard:

  1. Navigate to Workers & Pages
  2. Select your Worker
  3. Settings → Domains & Routes
  4. Add custom domain

DNS: Domain must be on Cloudflare (zone required)

TypeScript Support

Generate types for Cloudflare bindings:

npm run cf-typegen

Creates cloudflare-env.d.ts with types for your bindings:

// cloudflare-env.d.ts (auto-generated)
interface CloudflareEnv {
  DB: D1Database;
  BUCKET: R2Bucket;
  KV: KVNamespace;
  AI: Ai;
}

Use in route handlers:

import type { NextRequest } from 'next/server';

export async function GET(request: NextRequest) {
  const env = process.env as CloudflareEnv;
  // Now env.DB, env.BUCKET, etc. are typed
}

Testing

Local Testing (Development)

# Next.js dev server (fast iteration)
npm run dev

Local Testing (Production-like)

# Workerd runtime (catches Workers-specific issues)
npm run preview

Integration Testing

Always test in preview mode before deploying:

# Build and run in workerd
npm run preview

# Test bindings (D1, R2, KV, AI)
# Test middleware
# Test API routes
# Test SSR/ISR behavior

Migration from Other Platforms

From Vercel

  1. Copy existing Next.js project
  2. Run existing project migration steps (above)
  3. Update environment variables in Cloudflare dashboard
  4. Replace Vercel-specific features:

- Vercel Postgres → Cloudflare D1 - Vercel Blob → Cloudflare R2 - Vercel KV → Cloudflare KV - Vercel Edge Config → Cloudflare KV

  1. Test thoroughly with npm run preview
  2. Deploy with npm run deploy

From AWS / Other Platforms

Same process as Vercel migration - the adapter handles Next.js standard features automatically.

Resources

Official Documentation

Troubleshooting

Related Skills

  • cloudflare-worker-base - Base Worker setup with Hono + Vite + React
  • cloudflare-d1 - D1 database integration
  • cloudflare-r2 - R2 object storage
  • cloudflare-kv - KV key-value storage
  • cloudflare-workers-ai - Workers AI integration
  • cloudflare-vectorize - Vector database for RAG

Quick Reference

Essential Commands

# New project
npm create cloudflare@latest -- my-next-app --framework=next

# Development
npm run dev      # Fast iteration (Next.js dev server)
npm run preview  # Test in workerd (production-like)

# Deployment
npm run deploy   # Build and deploy to Cloudflare

# TypeScript
npm run cf-typegen  # Generate binding types

Critical Configuration

// wrangler.jsonc
{
  "compatibility_date": "2025-05-05",  // Minimum!
  "compatibility_flags": ["nodejs_compat"]  // Required!
}

Common Pitfalls

  1. ❌ Using Edge runtime → ✅ Use Node.js runtime
  2. ❌ Global DB clients → ✅ Request-scoped clients
  3. ❌ Old compatibility_date → ✅ Use 2025-05-05+
  4. ❌ Missing nodejs_compat → ✅ Add to compatibility_flags
  5. ❌ Only testing in dev → ✅ Always test preview before deploy
  6. ❌ Using Turbopack → ✅ Use standard Next.js build

Production Tested: Official Cloudflare support and active community Token Savings: ~59% vs manual setup Errors Prevented: 10+ documented issues Last Verified: 2025-10-21

平台分布

Gemini CLI

27.72%
按下载量换算198

Antigravity

21.24%
按下载量换算151

Claude Code

16.87%
按下载量换算120

Cursor

12.2%
按下载量换算87

OpenCode

7.46%
按下载量换算53

github-copilot

3.17%
按下载量换算23

安全审计

Gen Agent Trust Hub

可疑

Socket

通过

Snyk

通过

权限和风险

接触敏感数据

该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在提醒或未通过项,安装前请自行复核。

继续浏览同类 Skills