Installation
Install the required dependencies:Configuration
import alchemy from "alchemy";
import { D1Database, KVNamespace, Nextjs } from "alchemy/cloudflare";
const app = await alchemy("my-nextjs-app");
const [db, cache] = await Promise.all([
D1Database("database", {
name: `${app.name}-${app.stage}-db`,
}),
KVNamespace("cache", {
title: `${app.name}-${app.stage}-cache`,
}),
]);
const website = await Nextjs("website", {
bindings: {
DB: db,
CACHE: cache,
API_SECRET: alchemy.secret.env.API_SECRET,
},
});
console.log({
url: website.url,
});
await app.finalize();
Configuration Options
Properties
bindings: Cloudflare bindings (KV, R2, D1, etc.)build: Build command override- Default:
opennextjs-cloudflare build
- Default:
dev: Dev command override- Default:
next dev
- Default:
entrypoint: Worker entrypoint path- Default:
.open-next/worker.js
- Default:
assets: Static assets directory- Default:
.open-next/assets
- Default:
noBundle: Skip bundling (useful for debugging)- Default:
false
- Default:
Build Configuration
The Next.js resource automatically:- Runs OpenNext Cloudflare build
- Bundles the worker with minification
- Sets
nodejs_compatcompatibility flag - Configures environment variables
Custom Build Command
Development Server
Customize the development server configuration:Accessing Bindings
Access Cloudflare bindings in your Next.js app using the platform env:Compatibility Flags
The Next.js resource automatically sets:nodejs_compat- Node.js compatibilityglobal_fetch_strictly_public- Fetch API compatibility
Limitations
- Not all Next.js features are supported on Cloudflare Workers
- Consult the OpenNext Cloudflare documentation for current limitations
- Some Node.js APIs may not be available
Related Resources
- Website - Base resource for web applications
- Worker - Cloudflare Workers deployment
- D1 Database - SQL database