cloudflare.config.ts is the typed configuration file for a Workers project.
Its default export can define a Worker, Container applications, and account
settings. Because the file is a TypeScript module, it can use imports,
functions, environment variables, and asynchronous values.
Loading cloudflare.config.ts requires Node.js 22.18 or later. Bun is not
supported: when cf runs on Bun, loading the file fails with
cloudflare.config.ts loading is not supported on Bun. Most cf commands load
the nearest cloudflare.config.ts, including commands that only call the
Cloudflare API, so this is the practical minimum for any cf command you run
inside the project.
Set "type": "module" in the project's package.json. Without it, Node.js
prints a warning each time it loads the file. With "type": "commonjs",
loading fails with Cannot use import statement outside a module.
Import the configuration helpers from cf/config. Add cf as a development
dependency so the project can resolve that import. Projects created with
cf init already include it.
npm i -D cfyarn add -D cfpnpm add -D cfbun add -d cfA Worker requires name and compatibilityDate. A Worker that runs code also
requires entrypoint.
Select a highlighted line to show its type and description below it.
export default defineConfig({ (defineConfig reference)
defineConfigFunctionLink to defineConfig
defineConfig<T extends ConfigInput<CloudflareConfig>>(config: T): T;Defines the default export of cloudflare.config.ts. Pass a configuration object, a promise that resolves to one, or a function that receives the config context (isPreview and mode) and returns either.
worker: { (worker reference)
workerOptionalLink to worker
worker?: ConfigInput<WorkerConfig>The Worker defined by this configuration.
name: "example-worker", (name reference)
entrypoint, (entrypoint reference)
entrypointOptionalLink to entrypoint
entrypoint?: string | WorkerModuleThe entrypoint module that will be executed. May be either a path string (e.g. "./src/index.ts") or a module namespace imported with the cf-worker import attribute.
compatibilityDate: "<COMPATIBILITY_DATE>", (compatibilityDate reference)
compatibilityDateRequiredLink to compatibilityDate
compatibilityDate: stringA date in the form yyyy-mm-dd, which will be used to determine which version of the Workers runtime is used. More details at https://developers.cloudflare.com/workers/configuration/compatibility-dates
The cf-worker import attribute lets TypeScript infer the Worker module,
binding types, and exported classes.
An assets-only Worker can omit entrypoint. Its build implementation must
provide the asset source. A deployable build must contain a Worker bundle,
static assets, or both.
cloudflare.config.ts does not have an assets.directory field. In Vite
projects, the static assets are the output of Vite's client build, which
includes Vite's publicDir directory (public by default). Projects that build
with Wrangler set the directory in a generated wrangler.config.ts file. For
details, refer to How cf runs your project.
Use defineConfig() for the default export. The helper returns the value you
pass to it and preserves literal values for TypeScript inference.
| Field | Required | Purpose |
|---|---|---|
accountId |
No | Sets the default account for cf commands |
complianceRegion |
No | Selects public or fedramp-high |
worker |
Development and builds | Defines the Worker |
containers |
No | Defines Container applications |
cf API commands can read an account-only default export. The Cloudflare Vite
plugin and Wrangler require worker for development and builds.
Use the configuration explorer to inspect the generated fields, builder methods, and nested options.
Select a highlighted line to show its type and description below it.
export default defineConfig(({ mode }) => { (defineConfig, mode reference)
defineConfigFunctionLink to defineConfig
defineConfig<T extends ConfigInput<CloudflareConfig>>(config: T): T;Defines the default export of cloudflare.config.ts. Pass a configuration object, a promise that resolves to one, or a function that receives the config context (isPreview and mode) and returns either.
modeContext valueLink to mode
mode: string | undefinedThe mode the config is being evaluated in. Set via the --mode CLI flag. In Vite the mode defaults to development in vite dev and production in vite build (more info). In Wrangler the mode defaults to undefined.
accountId: "<ACCOUNT_ID>", (accountId reference)
accountIdOptionalLink to accountId
accountId?: stringThis is the ID of the account associated with your zone. It can also be specified through the CLOUDFLARE_ACCOUNT_ID environment variable.
complianceRegion: "public", (complianceRegion reference)
complianceRegionOptionalLink to complianceRegion
complianceRegion?: "public" | "fedramp-high"The compliance boundary in which commands should operate. When omitted, this can be supplied through CLOUDFLARE_COMPLIANCE_REGION.
worker: { (worker reference)
workerOptionalLink to worker
worker?: ConfigInput<WorkerConfig>The Worker defined by this configuration.
name: isStaging ? "example-staging" : "example-worker", (name reference)
entrypoint, (entrypoint reference)
entrypointOptionalLink to entrypoint
entrypoint?: string | WorkerModuleThe entrypoint module that will be executed. May be either a path string (e.g. "./src/index.ts") or a module namespace imported with the cf-worker import attribute.
compatibilityDate: "<COMPATIBILITY_DATE>", (compatibilityDate reference)
compatibilityDateRequiredLink to compatibilityDate
compatibilityDate: stringA date in the form yyyy-mm-dd, which will be used to determine which version of the Workers runtime is used. More details at https://developers.cloudflare.com/workers/configuration/compatibility-dates
env: { (env reference)
envOptionalLink to env
env?: Record<string, Binding>Bindings exposed on the Worker's env object. Construct entries with bindings.kv(...), bindings.r2(...), etc.
MESSAGE: bindings.text(isStaging ? "staging" : "production"), (text reference)
textBuilderLink to text
text<T$1 extends string>(value: T$1): TextBinding<T$1>;Inline string value made available to the Worker on env under the binding name. For reference, see https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
triggers: [triggers.scheduled({ schedule: "0 * * * *" })], (triggers, scheduled, schedule reference)
triggersOptionalLink to triggers
triggers?: Trigger[]Event triggers — fetch routes, queue consumers, cron schedules, Email Routing addresses, and raw sockets — that invoke this Worker. Construct entries with triggers.fetch(...), triggers.queue(...), triggers.scheduled(...), triggers.email(...), or triggers.connect(...). For reference, see https://developers.cloudflare.com/workers/wrangler/configuration/#triggers
scheduledBuilderLink to scheduled
scheduled(options: ScheduledTriggerOptions): ScheduledTrigger;Scheduled (cron) trigger — invokes this Worker on the given schedules. More details here https://developers.cloudflare.com/workers/platform/cron-triggers
scheduleRequiredLink to schedule
schedule: stringA "cron" definition to trigger a Worker's "scheduled" function. Lets you call Workers periodically, much like a cron job. More details here https://developers.cloudflare.com/workers/platform/cron-triggers
defineConfig(), defineWorker(), and defineContainer() each accept an
object, a promise, or a function. A function can return an object or a promise.
Functions receive this context:
| Property | Purpose |
|---|---|
mode |
Identifies the selected mode, which depends on the command when you omit --mode |
isPreview |
Is true when the configuration is evaluated for a Worker Preview |
Return one complete configuration for each mode. Programmatic configuration does not merge environment blocks.
Use defineWorker() when another configuration file needs to import a Worker
definition. Use defineContainer() when a Durable Object export and the
containers array need to reference the same Container.
These helpers do not replace the default export. The default export must still
use defineConfig().
The worker object supports these fields:
| Field | Required | Purpose |
|---|---|---|
name |
Yes | Sets the Worker name |
compatibilityDate |
Yes | Selects a Workers runtime compatibility date |
entrypoint |
Conditional | Selects the Worker module |
assets |
No | Sets runtime request behavior for built assets |
cache |
No | Configures Worker cache behavior |
compatibilityFlags |
No | Turns on runtime compatibility flags |
domains |
No | Publishes the Worker to custom domains |
env |
No | Declares bindings and inline values |
exports |
No | Configures named Worker, Durable Object, and Workflow exports |
limits |
No | Sets CPU and subrequest limits |
logpush |
No | Sends trace events to Workers Logpush |
observability |
No | Configures logs, traces, and sampling |
placement |
No | Configures smart or targeted placement |
previewUrls |
No | Controls version preview URLs |
tailConsumers |
No | Sends events to Tail Workers |
triggers |
No | Declares routes, queues, schedules, and sockets |
unsafe |
No | Passes unsupported metadata through to deployment |
workersDev |
No | Controls the workers.dev route |
The assets object controls runtime behavior only. It configures HTML
handling, not-found handling, and whether matching requests run the Worker
first. It does not select the asset source.
Use domains for custom domains. Use triggers.fetch() for routes.
The bindings, triggers, and exports builders return ordinary
configuration objects. Each object has a literal type field that identifies
its kind.
The type field lets TypeScript select the valid options for each kind. For
example, a queue trigger accepts batching options, while a scheduled trigger
requires a cron expression. The configuration loader uses the same fields for
runtime validation.
Use builders instead of writing type fields directly. Builders preserve
literal values and generic type arguments for Worker type inference.
Each key under worker.env becomes a binding name in Worker code. The builder
method selects the binding's runtime type.
This configuration declares inline values, a D1 database, a Queue, and a secret:
Select a highlighted line to show its type and description below it.
export default defineConfig({ (defineConfig reference)
defineConfigFunctionLink to defineConfig
defineConfig<T extends ConfigInput<CloudflareConfig>>(config: T): T;Defines the default export of cloudflare.config.ts. Pass a configuration object, a promise that resolves to one, or a function that receives the config context (isPreview and mode) and returns either.
worker: { (worker reference)
workerOptionalLink to worker
worker?: ConfigInput<WorkerConfig>The Worker defined by this configuration.
name: "example-worker", (name reference)
entrypoint, (entrypoint reference)
entrypointOptionalLink to entrypoint
entrypoint?: string | WorkerModuleThe entrypoint module that will be executed. May be either a path string (e.g. "./src/index.ts") or a module namespace imported with the cf-worker import attribute.
compatibilityDate: "<COMPATIBILITY_DATE>", (compatibilityDate reference)
compatibilityDateRequiredLink to compatibilityDate
compatibilityDate: stringA date in the form yyyy-mm-dd, which will be used to determine which version of the Workers runtime is used. More details at https://developers.cloudflare.com/workers/configuration/compatibility-dates
env: { (env reference)
envOptionalLink to env
env?: Record<string, Binding>Bindings exposed on the Worker's env object. Construct entries with bindings.kv(...), bindings.r2(...), etc.
API_ORIGIN: bindings.text("https://api.example.com"), (text reference)
textBuilderLink to text
text<T$1 extends string>(value: T$1): TextBinding<T$1>;Inline string value made available to the Worker on env under the binding name. For reference, see https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
FEATURES: bindings.json({ search: true }), (json reference)
jsonBuilderLink to json
json<T$1 extends Json>(value: T$1): JsonBinding<T$1>;Inline JSON value made available to the Worker on env under the binding name.
DATABASE: bindings.d1({ name: "application-db" }), (d1, name reference)
d1BuilderLink to d1
d1(options?: D1BindingOptions): D1Binding;Binding to a D1 database. For reference, see https://developers.cloudflare.com/workers/wrangler/configuration/#d1-databases
JOBS: bindings.queue<Job>({ name: "application-jobs" }), (queue, name reference)
queueBuilderLink to queue
queue<TBody = unknown>(options?: QueueBindingOptions): TypedQueueBinding<TBody>;Producer binding to a Cloudflare Queue. For reference, see https://developers.cloudflare.com/workers/wrangler/configuration/#queues
API_KEY: bindings.secret(), (secret reference)
secretBuilderLink to secret
secret(): SecretBinding;Declares a secret that is required by your Worker, exposed on env under the binding name. When defined, this binding: - Replaces .dev.vars/.env/process.env inference for type generation - Enables local dev validation with warnings for missing secrets For reference, see https://developers.cloudflare.com/workers/wrangler/configuration/#secrets-configuration-property
The generated Env type contains these runtime types:
| Binding | Inferred runtime type |
|---|---|
API_ORIGIN |
"https://api.example.com" |
FEATURES |
{ search: true } |
DATABASE |
D1Database |
JOBS |
Queue<Job> |
API_KEY |
string |
Your Worker receives the inferred type through env:
export default {
async fetch(_request, env) {
await env.JOBS.send({
id: "example-job",
operation: "index",
});
const result = await env.DATABASE.prepare("SELECT 1").first();
return Response.json({
origin: env.API_ORIGIN,
search: env.FEATURES.search,
result,
});
},
};export default {
async fetch(_request, env) {
await env.JOBS.send({
id: "example-job",
operation: "index",
});
const result = await env.DATABASE.prepare("SELECT 1").first();
return Response.json({
origin: env.API_ORIGIN,
search: env.FEATURES.search,
result,
});
},
} satisfies ExportedHandler<Env>;The Cloudflare Vite plugin writes .cloudflare/types/index.d.ts during
development and builds. Outside the Vite workflow, cf workers types writes the
same file.
TypeScript wildcard patterns skip dot-prefixed directories, so include the
generated directory explicitly. The .ts extensions in the examples on this
page also need allowImportingTsExtensions:
{
"compilerOptions": {
"allowImportingTsExtensions": true,
"noEmit": true
},
"include": ["src", "cloudflare.config.ts", ".cloudflare/types"]
}The builder API includes these methods:
| Area | Builder methods |
|---|---|
| Inline values | text, json, secret |
| Storage and data | d1, kv, r2, hyperdrive, analyticsEngineDataset, artifacts, pipeline |
| AI and media | ai, aiSearch, aiSearchNamespace, agentMemory, browser, images, media, stream, vectorize |
| Messaging | queue, sendEmail |
| Worker composition | assets, dispatchNamespace, durableObject, worker, workerLoader, workflow |
| Network and security | mtlsCertificate, rateLimit, secretsStoreSecret, vpcNetwork, vpcService |
| Platform metadata | flagship, logfwdr, versionMetadata |
Required options differ by binding. TypeScript completion shows the options for each builder.
bindings.worker(), bindings.durableObject(), and bindings.workflow()
accept a Worker name or a Worker definition. Import a Worker definition to
validate its export names at compile time.
For example, an API Worker can export its definition:
Select a highlighted line to show its type and description below it.
export const apiWorker = defineWorker({ (defineWorker reference)
defineWorkerFunctionLink to defineWorker
defineWorker<T extends ConfigInput<WorkerConfig>>(config: T): T;Defines a Worker configuration that you can pass to worker in defineConfig(). Pass a Worker configuration object, a promise that resolves to one, or a function that receives the config context (isPreview and mode) and returns either.
name: "api-worker", (name reference)
entrypoint, (entrypoint reference)
entrypointOptionalLink to entrypoint
entrypoint?: string | WorkerModuleThe entrypoint module that will be executed. May be either a path string (e.g. "./src/index.ts") or a module namespace imported with the cf-worker import attribute.
compatibilityDate: "<COMPATIBILITY_DATE>", (compatibilityDate reference)
compatibilityDateRequiredLink to compatibilityDate
compatibilityDate: stringA date in the form yyyy-mm-dd, which will be used to determine which version of the Workers runtime is used. More details at https://developers.cloudflare.com/workers/configuration/compatibility-dates
exports: { (exports reference)
exportsOptionalLink to exports
exports?: Record<string, Export>Configuration for named exports declared by the Worker. Each entry's key is the exported class name; the value configures the export. - Construct entries with exports.durableObject(...). - Declares Durable Object classes exported from this Worker. For more information about Durable Objects, see the documentation at https://developers.cloudflare.com/workers/learning/using-durable-objects. For reference, see https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects. - Construct entries with exports.workflow(...). - Declares Workflows defined by this Worker. For more information about Workflows, see the documentation at https://developers.cloudflare.com/workflows/.
Admin: exports.worker(), (worker reference)
workerBuilderLink to worker
worker(options?: WorkerEntrypointExportOptions): WorkerEntrypointExport;Declares a WorkerEntrypoint export defined by this Worker.
Counter: exports.durableObject({ storage: "sqlite" }), (durableObject, storage reference)
durableObjectBuilderLink to durableObject
durableObject<TContainer extends ContainerDefinition | undefined = undefined>(options: DurableObjectCreatedExportOptions<TContainer>): DurableObjectCreatedExport<TContainer>;Declares a Durable Object class defined by this Worker. For more information about Durable Objects, see the documentation at https://developers.cloudflare.com/workers/learning/using-durable-objects For reference, see https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects
storageRequiredLink to storage
storage: "sqlite" | "legacy-kv"Selects the SQLite-backed storage engine (recommended for new classes). Selects the legacy key-value storage engine.
export default defineConfig({ worker: apiWorker }); (defineConfig, worker reference)
defineConfigFunctionLink to defineConfig
defineConfig<T extends ConfigInput<CloudflareConfig>>(config: T): T;Defines the default export of cloudflare.config.ts. Pass a configuration object, a promise that resolves to one, or a function that receives the config context (isPreview and mode) and returns either.
workerOptionalLink to worker
worker?: ConfigInput<WorkerConfig>The Worker defined by this configuration.
A second Worker can import that definition:
Select a highlighted line to show its type and description below it.
export default defineConfig({ (defineConfig reference)
defineConfigFunctionLink to defineConfig
defineConfig<T extends ConfigInput<CloudflareConfig>>(config: T): T;Defines the default export of cloudflare.config.ts. Pass a configuration object, a promise that resolves to one, or a function that receives the config context (isPreview and mode) and returns either.
worker: { (worker reference)
workerOptionalLink to worker
worker?: ConfigInput<WorkerConfig>The Worker defined by this configuration.
name: "web-worker", (name reference)
entrypoint, (entrypoint reference)
entrypointOptionalLink to entrypoint
entrypoint?: string | WorkerModuleThe entrypoint module that will be executed. May be either a path string (e.g. "./src/index.ts") or a module namespace imported with the cf-worker import attribute.
compatibilityDate: "<COMPATIBILITY_DATE>", (compatibilityDate reference)
compatibilityDateRequiredLink to compatibilityDate
compatibilityDate: stringA date in the form yyyy-mm-dd, which will be used to determine which version of the Workers runtime is used. More details at https://developers.cloudflare.com/workers/configuration/compatibility-dates
env: { (env reference)
envOptionalLink to env
env?: Record<string, Binding>Bindings exposed on the Worker's env object. Construct entries with bindings.kv(...), bindings.r2(...), etc.
API: bindings.worker({ (worker reference)
workerBuilderLink to worker
worker<TWorker$1 extends WorkerReference, TExportName$1 extends WorkerEntrypointExportName<TWorker$1> | undefined = undefined>(options: WorkerBindingOptions<TWorker$1, TExportName$1>): WorkerBinding<TWorker$1, NoInfer<TExportName$1>>;Service binding (Worker-to-Worker). worker is the name or config of the bound Worker; exportName selects a named WorkerEntrypoint export (defaults to the default export). For reference, see https://developers.cloudflare.com/workers/wrangler/configuration/#service-bindings
worker: apiWorker, (worker reference)
exportName: "Admin", (exportName reference)
exportNameOptionalLink to exportName
exportName?: TExportName$1The named export to bind to (defaults to the default export).
COUNTERS: bindings.durableObject({ (durableObject reference)
durableObjectBuilderLink to durableObject
durableObject<TWorker$1 extends WorkerReference, TExportName$1 extends DurableObjectExportName<TWorker$1>>(options: DurableObjectBindingOptions<TWorker$1, TExportName$1>): DurableObjectBinding<TWorker$1, TExportName$1>;Binding to a Durable Object class. worker is the name or config of the Worker that defines the class; exportName is the exported class name. For reference, see https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects
worker: apiWorker, (worker reference)
workerRequiredLink to worker
worker: TWorker$1The name or config of the Worker that defines the Durable Object class.
exportName: "Counter", (exportName reference)
exportNameRequiredLink to exportName
exportName: TExportName$1The exported class name of the Durable Object.
Import the other configuration file with its .ts extension. Node.js loads
cloudflare.config.ts with its own module resolution, which does not add
extensions. An import without the extension fails with a Cannot find module
error (ERR_MODULE_NOT_FOUND). Because API commands also load the nearest
configuration file, the error breaks ordinary API commands in that directory
too.
TypeScript rejects unknown export names. It also infers the API Remote
Procedure Call (RPC) methods and the Durable Object stub type from the imported
entrypoint.
Use a Worker name when the target definition cannot be imported. TypeScript can validate the binding shape, but it cannot validate the remote export name.
Each triggers method returns a typed event declaration. Add these values to
the worker.triggers array.
Select a highlighted line to show its type and description below it.
export default defineConfig({ (defineConfig reference)
defineConfigFunctionLink to defineConfig
defineConfig<T extends ConfigInput<CloudflareConfig>>(config: T): T;Defines the default export of cloudflare.config.ts. Pass a configuration object, a promise that resolves to one, or a function that receives the config context (isPreview and mode) and returns either.
worker: { (worker reference)
workerOptionalLink to worker
worker?: ConfigInput<WorkerConfig>The Worker defined by this configuration.
name: "example-worker", (name reference)
entrypoint, (entrypoint reference)
entrypointOptionalLink to entrypoint
entrypoint?: string | WorkerModuleThe entrypoint module that will be executed. May be either a path string (e.g. "./src/index.ts") or a module namespace imported with the cf-worker import attribute.
compatibilityDate: "<COMPATIBILITY_DATE>", (compatibilityDate reference)
compatibilityDateRequiredLink to compatibilityDate
compatibilityDate: stringA date in the form yyyy-mm-dd, which will be used to determine which version of the Workers runtime is used. More details at https://developers.cloudflare.com/workers/configuration/compatibility-dates
triggers: [ (triggers reference)
triggersOptionalLink to triggers
triggers?: Trigger[]Event triggers — fetch routes, queue consumers, cron schedules, Email Routing addresses, and raw sockets — that invoke this Worker. Construct entries with triggers.fetch(...), triggers.queue(...), triggers.scheduled(...), triggers.email(...), or triggers.connect(...). For reference, see https://developers.cloudflare.com/workers/wrangler/configuration/#triggers
triggers.fetch({ (fetch reference)
fetchBuilderLink to fetch
fetch(options: FetchTriggerOptions): FetchTrigger;Fetch trigger — a route that your Worker should be published to. For reference, see https://developers.cloudflare.com/workers/wrangler/configuration/#types-of-routes
pattern: "api.example.com/*", (pattern reference)
patternRequiredLink to pattern
pattern: stringA route that your Worker should be published to. For reference, see https://developers.cloudflare.com/workers/wrangler/configuration/#types-of-routes
zone: "example.com", (zone reference)
zoneOptionalLink to zone
zone?: stringThe DNS zone the pattern is attached to. Required when the pattern is ambiguous.
triggers.queue({ (queue reference)
queueBuilderLink to queue
queue(options: QueueConsumerTriggerOptions): QueueConsumerTrigger;Queue consumer trigger — invokes this Worker when messages arrive on the named queue. For reference, see https://developers.cloudflare.com/workers/wrangler/configuration/#queues
name: "application-jobs", (name reference)
maxBatchSize: 10, (maxBatchSize reference)
maxBatchSizeOptionalLink to maxBatchSize
maxBatchSize?: numberThe maximum number of messages per batch.
maxRetries: 3, (maxRetries reference)
maxRetriesOptionalLink to maxRetries
maxRetries?: numberThe maximum number of retries for each message.
triggers.scheduled({ schedule: "0 * * * *" }), (scheduled, schedule reference)
scheduledBuilderLink to scheduled
scheduled(options: ScheduledTriggerOptions): ScheduledTrigger;Scheduled (cron) trigger — invokes this Worker on the given schedules. More details here https://developers.cloudflare.com/workers/platform/cron-triggers
scheduleRequiredLink to schedule
schedule: stringA "cron" definition to trigger a Worker's "scheduled" function. Lets you call Workers periodically, much like a cron job. More details here https://developers.cloudflare.com/workers/platform/cron-triggers
triggers.email({ addresses: ["support@example.com"] }), (email, addresses reference)
emailBuilderLink to email
email(options: EmailTriggerOptions): EmailTrigger;Email trigger — invokes this Worker for the configured Email Routing addresses.
addressesRequiredLink to addresses
addresses: string[]Inbound Email Routing addresses handled by this Worker. Each entry is a literal recipient address (e.g. "support@example.com") or a *@domain catch-all (e.g. "*@example.com").
triggers.connect({ protocol: "tcp", port: 5432 }), (connect, protocol, port reference)
connectBuilderLink to connect
connect(options: ConnectTriggerOptions): ConnectTrigger;Connect trigger — invokes this Worker's connect(socket, env, ctx) handler for raw socket connections received on the configured protocol/port.
protocolRequiredLink to protocol
protocol: "tcp" | "udp"The type definition does not include a description.
The builder provides these trigger methods:
| Method | Event |
|---|---|
fetch |
A route receives HTTP traffic |
queue |
A queue delivers messages |
scheduled |
A cron schedule runs |
email |
Email Routing receives matching email |
connect |
TCP or UDP traffic reaches the configured port |
Set protocol to "tcp" or "udp" in triggers.connect(). UDP triggers also
accept idleTimeoutMs and maxPendingBytes.
Triggers control which events invoke a Worker. They do not create env
bindings. TypeScript checks the options for each trigger, while Workers runtime
types provide the handler signatures.
The worker.exports map describes how the platform manages module exports.
Each key must match the default export or a named class exported by the
entrypoint.
Use exports.worker() to configure a WorkerEntrypoint. It accepts an
optional per-entrypoint cache setting. Use exports.durableObject() to declare
a Durable Object class and its lifecycle state. Use exports.workflow() to
declare a class that extends WorkflowEntrypoint.
Select a highlighted line to show its type and description below it.
export default defineConfig({ (defineConfig reference)
defineConfigFunctionLink to defineConfig
defineConfig<T extends ConfigInput<CloudflareConfig>>(config: T): T;Defines the default export of cloudflare.config.ts. Pass a configuration object, a promise that resolves to one, or a function that receives the config context (isPreview and mode) and returns either.
worker: { (worker reference)
workerOptionalLink to worker
worker?: ConfigInput<WorkerConfig>The Worker defined by this configuration.
name: "example-worker", (name reference)
entrypoint, (entrypoint reference)
entrypointOptionalLink to entrypoint
entrypoint?: string | WorkerModuleThe entrypoint module that will be executed. May be either a path string (e.g. "./src/index.ts") or a module namespace imported with the cf-worker import attribute.
compatibilityDate: "<COMPATIBILITY_DATE>", (compatibilityDate reference)
compatibilityDateRequiredLink to compatibilityDate
compatibilityDate: stringA date in the form yyyy-mm-dd, which will be used to determine which version of the Workers runtime is used. More details at https://developers.cloudflare.com/workers/configuration/compatibility-dates
exports: { (exports reference)
exportsOptionalLink to exports
exports?: Record<string, Export>Configuration for named exports declared by the Worker. Each entry's key is the exported class name; the value configures the export. - Construct entries with exports.durableObject(...). - Declares Durable Object classes exported from this Worker. For more information about Durable Objects, see the documentation at https://developers.cloudflare.com/workers/learning/using-durable-objects. For reference, see https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects. - Construct entries with exports.workflow(...). - Declares Workflows defined by this Worker. For more information about Workflows, see the documentation at https://developers.cloudflare.com/workflows/.
default: exports.worker({ cache: { enabled: false } }), (worker, cache, enabled reference)
workerBuilderLink to worker
worker(options?: WorkerEntrypointExportOptions): WorkerEntrypointExport;Declares a WorkerEntrypoint export defined by this Worker.
cacheOptionalLink to cache
cache?: { /** Whether cache is enabled for this entrypoint. */ enabled: boolean; }The type definition does not include a description.
Admin: exports.worker({ cache: { enabled: true } }), (worker, cache, enabled reference)
workerBuilderLink to worker
worker(options?: WorkerEntrypointExportOptions): WorkerEntrypointExport;Declares a WorkerEntrypoint export defined by this Worker.
cacheOptionalLink to cache
cache?: { /** Whether cache is enabled for this entrypoint. */ enabled: boolean; }The type definition does not include a description.
Counter: exports.durableObject({ storage: "sqlite" }), (durableObject, storage reference)
durableObjectBuilderLink to durableObject
durableObject<TContainer extends ContainerDefinition | undefined = undefined>(options: DurableObjectCreatedExportOptions<TContainer>): DurableObjectCreatedExport<TContainer>;Declares a Durable Object class defined by this Worker. For more information about Durable Objects, see the documentation at https://developers.cloudflare.com/workers/learning/using-durable-objects For reference, see https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects
storageRequiredLink to storage
storage: "sqlite" | "legacy-kv"Selects the SQLite-backed storage engine (recommended for new classes). Selects the legacy key-value storage engine.
OrderWorkflow: exports.workflow({ (workflow reference)
workflowBuilderLink to workflow
workflow(options: WorkflowExportOptions): WorkflowExport;Declares a Workflow defined by this Worker. The export's key must name a class that extends WorkflowEntrypoint. For more information about Workflows, see the documentation at https://developers.cloudflare.com/workflows/
name: "order-workflow", (name reference)
nameRequiredLink to name
name: stringThe name of the Workflow. It identifies the Workflow's instances and must be unique within the account.
limits: { steps: 100 }, (limits, steps reference)
limitsOptionalLink to limits
limits?: { /** Maximum number of steps a single Workflow instance may run. */ steps?: number; }The type definition does not include a description.
defaultRetention: { (defaultRetention reference)
defaultRetentionOptionalLink to defaultRetention
defaultRetention?: { /** How long to retain instances that completed successfully or were terminated. */ successRetention?: number | string; /** How long to retain errored instances. */ errorRetention?: number | string; }Default retention for instances of this Workflow, applied when an instance does not set its own retention. Accepts milliseconds or a duration string such as "3 days".
successRetention: "3 days", (successRetention reference)
successRetentionOptionalLink to successRetention
successRetention?: number | stringHow long to retain instances that completed successfully or were terminated.
errorRetention: "7 days", (errorRetention reference)
errorRetentionOptionalLink to errorRetention
errorRetention?: number | stringHow long to retain errored instances.
The builders describe exported code. They do not create JavaScript exports. The
entrypoint must still export Admin, Counter, and OrderWorkflow.
exports.workflow() requires a name, which must be unique within the account.
It also accepts limits.steps, concurrency.limit, schedules for cron
schedules that start instances, and defaultRetention. Retention values accept
milliseconds or a duration string, such as "3 days".
To bind to a Workflow, from the same Worker or another one, use
bindings.workflow(). It requires the Workflow's name, the worker that
defines it (a Worker name or a Worker definition), and the exportName of its
class, such as
bindings.workflow({ name: "order-workflow", worker: "example-worker", exportName: "OrderWorkflow" }).
The exports map replaces an ordered Durable Object migration history. Keep
live classes in the map. Add temporary tombstones when a class is deleted,
renamed, or transferred.
The key of each entry is the Durable Object class name. The state field
selects the valid lifecycle options:
| State | Purpose |
|---|---|
created or omitted |
Declares a live class with sqlite or legacy-kv storage |
deleted |
Retires a namespace after its class is removed |
renamed |
Renames the key to the live class named by renamedTo |
expecting-transfer |
Prepares the destination Worker to receive a namespace from transferFrom |
transferred |
Transfers ownership to the same-account Worker named by transferredTo |
Use sqlite for new classes. A live or incoming class that uses sqlite can
attach a Container definition. You cannot attach a Container to a
legacy-kv class or a tombstone.
Exports and bindings serve different purposes:
| Configuration | Purpose |
|---|---|
exports.Counter |
Declares the class and manages its namespace lifecycle |
env.COUNTERS |
Injects a namespace binding under env.COUNTERS |
ctx.exports.Counter |
Accesses a class exported by the same Worker without an env binding |
Live Durable Object exports become typed properties on ctx.exports. A Worker
does not need an env binding to call its own class.
Select a highlighted line to show its type and description below it.
export default defineConfig({ (defineConfig reference)
defineConfigFunctionLink to defineConfig
defineConfig<T extends ConfigInput<CloudflareConfig>>(config: T): T;Defines the default export of cloudflare.config.ts. Pass a configuration object, a promise that resolves to one, or a function that receives the config context (isPreview and mode) and returns either.
worker: { (worker reference)
workerOptionalLink to worker
worker?: ConfigInput<WorkerConfig>The Worker defined by this configuration.
name: "counter-worker", (name reference)
entrypoint, (entrypoint reference)
entrypointOptionalLink to entrypoint
entrypoint?: string | WorkerModuleThe entrypoint module that will be executed. May be either a path string (e.g. "./src/index.ts") or a module namespace imported with the cf-worker import attribute.
compatibilityDate: "<COMPATIBILITY_DATE>", (compatibilityDate reference)
compatibilityDateRequiredLink to compatibilityDate
compatibilityDate: stringA date in the form yyyy-mm-dd, which will be used to determine which version of the Workers runtime is used. More details at https://developers.cloudflare.com/workers/configuration/compatibility-dates
compatibilityFlags: ["enable_ctx_exports"], (compatibilityFlags reference)
compatibilityFlagsOptionalLink to compatibilityFlags
compatibilityFlags?: string[]A list of flags that enable features from upcoming features of the Workers runtime, usually used together with compatibilityDate. More details at https://developers.cloudflare.com/workers/configuration/compatibility-flags/
Default: []
exports: { (exports reference)
exportsOptionalLink to exports
exports?: Record<string, Export>Configuration for named exports declared by the Worker. Each entry's key is the exported class name; the value configures the export. - Construct entries with exports.durableObject(...). - Declares Durable Object classes exported from this Worker. For more information about Durable Objects, see the documentation at https://developers.cloudflare.com/workers/learning/using-durable-objects. For reference, see https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects. - Construct entries with exports.workflow(...). - Declares Workflows defined by this Worker. For more information about Workflows, see the documentation at https://developers.cloudflare.com/workflows/.
Counter: exports.durableObject({ storage: "sqlite" }), (durableObject, storage reference)
durableObjectBuilderLink to durableObject
durableObject<TContainer extends ContainerDefinition | undefined = undefined>(options: DurableObjectCreatedExportOptions<TContainer>): DurableObjectCreatedExport<TContainer>;Declares a Durable Object class defined by this Worker. For more information about Durable Objects, see the documentation at https://developers.cloudflare.com/workers/learning/using-durable-objects For reference, see https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects
storageRequiredLink to storage
storage: "sqlite" | "legacy-kv"Selects the SQLite-backed storage engine (recommended for new classes). Selects the legacy key-value storage engine.
import { DurableObject } from "cloudflare:workers";
export class Counter extends DurableObject {
getValue() {
return this.ctx.storage.get("value");
}
}
export default {
async fetch(_request, _env, ctx) {
const id = ctx.exports.Counter.idFromName("global");
const stub = ctx.exports.Counter.get(id);
return Response.json({ value: await stub.getValue() });
},
};import { DurableObject } from "cloudflare:workers";
export class Counter extends DurableObject {
getValue() {
return this.ctx.storage.get<number>("value");
}
}
export default {
async fetch(_request, _env, ctx) {
const id = ctx.exports.Counter.idFromName("global");
const stub = ctx.exports.Counter.get(id);
return Response.json({ value: await stub.getValue() });
},
} satisfies ExportedHandler<Env>;The generated types include live and incoming Durable Object exports.
Tombstones do not appear on ctx.exports.
A rename keeps the old name as a tombstone. The destination name must appear as a live entry in the same map. Remove the old class from the Worker code.
Select a highlighted line to show its type and description below it.
export default defineConfig({ (defineConfig reference)
defineConfigFunctionLink to defineConfig
defineConfig<T extends ConfigInput<CloudflareConfig>>(config: T): T;Defines the default export of cloudflare.config.ts. Pass a configuration object, a promise that resolves to one, or a function that receives the config context (isPreview and mode) and returns either.
worker: { (worker reference)
workerOptionalLink to worker
worker?: ConfigInput<WorkerConfig>The Worker defined by this configuration.
name: "counter-worker", (name reference)
entrypoint, (entrypoint reference)
entrypointOptionalLink to entrypoint
entrypoint?: string | WorkerModuleThe entrypoint module that will be executed. May be either a path string (e.g. "./src/index.ts") or a module namespace imported with the cf-worker import attribute.
compatibilityDate: "<COMPATIBILITY_DATE>", (compatibilityDate reference)
compatibilityDateRequiredLink to compatibilityDate
compatibilityDate: stringA date in the form yyyy-mm-dd, which will be used to determine which version of the Workers runtime is used. More details at https://developers.cloudflare.com/workers/configuration/compatibility-dates
exports: { (exports reference)
exportsOptionalLink to exports
exports?: Record<string, Export>Configuration for named exports declared by the Worker. Each entry's key is the exported class name; the value configures the export. - Construct entries with exports.durableObject(...). - Declares Durable Object classes exported from this Worker. For more information about Durable Objects, see the documentation at https://developers.cloudflare.com/workers/learning/using-durable-objects. For reference, see https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects. - Construct entries with exports.workflow(...). - Declares Workflows defined by this Worker. For more information about Workflows, see the documentation at https://developers.cloudflare.com/workflows/.
Counter: exports.durableObject({ storage: "sqlite" }), (durableObject, storage reference)
durableObjectBuilderLink to durableObject
durableObject<TContainer extends ContainerDefinition | undefined = undefined>(options: DurableObjectCreatedExportOptions<TContainer>): DurableObjectCreatedExport<TContainer>;Declares a Durable Object class defined by this Worker. For more information about Durable Objects, see the documentation at https://developers.cloudflare.com/workers/learning/using-durable-objects For reference, see https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects
storageRequiredLink to storage
storage: "sqlite" | "legacy-kv"Selects the SQLite-backed storage engine (recommended for new classes). Selects the legacy key-value storage engine.
OldCounter: exports.durableObject({ (durableObject reference)
durableObjectBuilderLink to durableObject
durableObject(options: DurableObjectRenamedExportOptions): DurableObjectRenamedExport;Rename a provisioned Durable Object namespace's class.
state: "renamed", (state reference)
renamedTo: "Counter", (renamedTo reference)
renamedToRequiredLink to renamedTo
renamedTo: stringThe destination class name. Must be a valid JavaScript identifier and must appear as a live (state: "created") durableObject entry in the same exports map.
UnusedCounter: exports.durableObject({ state: "deleted" }), (durableObject, state reference)
durableObjectBuilderLink to durableObject
durableObject(options: DurableObjectDeletedExportOptions): DurableObjectDeletedExport;Retire a provisioned Durable Object namespace whose class has been removed from code.
Before you delete a namespace, remove every binding to that class. The uploaded
Worker must not export a class marked as deleted.
Deployment responses identify stale tombstones that are safe to remove. Keep each tombstone until it appears in that response, then remove it from the map. You do not need to retain the complete migration history.
A namespace transfer uses two deployments. Both Workers must use the same Cloudflare account.
First, deploy the destination Worker with an incoming live entry:
Select a highlighted line to show its type and description below it.
export default defineConfig({ (defineConfig reference)
defineConfigFunctionLink to defineConfig
defineConfig<T extends ConfigInput<CloudflareConfig>>(config: T): T;Defines the default export of cloudflare.config.ts. Pass a configuration object, a promise that resolves to one, or a function that receives the config context (isPreview and mode) and returns either.
worker: { (worker reference)
workerOptionalLink to worker
worker?: ConfigInput<WorkerConfig>The Worker defined by this configuration.
name: "destination-worker", (name reference)
entrypoint, (entrypoint reference)
entrypointOptionalLink to entrypoint
entrypoint?: string | WorkerModuleThe entrypoint module that will be executed. May be either a path string (e.g. "./src/index.ts") or a module namespace imported with the cf-worker import attribute.
compatibilityDate: "<COMPATIBILITY_DATE>", (compatibilityDate reference)
compatibilityDateRequiredLink to compatibilityDate
compatibilityDate: stringA date in the form yyyy-mm-dd, which will be used to determine which version of the Workers runtime is used. More details at https://developers.cloudflare.com/workers/configuration/compatibility-dates
exports: { (exports reference)
exportsOptionalLink to exports
exports?: Record<string, Export>Configuration for named exports declared by the Worker. Each entry's key is the exported class name; the value configures the export. - Construct entries with exports.durableObject(...). - Declares Durable Object classes exported from this Worker. For more information about Durable Objects, see the documentation at https://developers.cloudflare.com/workers/learning/using-durable-objects. For reference, see https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects. - Construct entries with exports.workflow(...). - Declares Workflows defined by this Worker. For more information about Workflows, see the documentation at https://developers.cloudflare.com/workflows/.
Counter: exports.durableObject({ (durableObject reference)
durableObjectBuilderLink to durableObject
durableObject<TContainer extends ContainerDefinition | undefined = undefined>(options: DurableObjectExpectingTransferExportOptions<TContainer>): DurableObjectExpectingTransferExport<TContainer>;Prepare to receive cross-Worker Durable Object transfer. The source Worker must follow up with a deployment containing a transferred export to commit the transfer.
state: "expecting-transfer", (state reference)
stateRequiredLink to state
state: "expecting-transfer"The type definition does not include a description.
storage: "sqlite", (storage reference)
storageRequiredLink to storage
storage: "sqlite" | "legacy-kv"Selects the SQLite-backed storage engine (recommended for new classes). Selects the legacy key-value storage engine.
transferFrom: "source-worker", (transferFrom reference)
transferFromRequiredLink to transferFrom
transferFrom: stringThe source Worker for the two-phase cross-Worker transfer.
Then deploy the source Worker with a transfer tombstone:
Select a highlighted line to show its type and description below it.
export default defineConfig({ (defineConfig reference)
defineConfigFunctionLink to defineConfig
defineConfig<T extends ConfigInput<CloudflareConfig>>(config: T): T;Defines the default export of cloudflare.config.ts. Pass a configuration object, a promise that resolves to one, or a function that receives the config context (isPreview and mode) and returns either.
worker: { (worker reference)
workerOptionalLink to worker
worker?: ConfigInput<WorkerConfig>The Worker defined by this configuration.
name: "source-worker", (name reference)
entrypoint, (entrypoint reference)
entrypointOptionalLink to entrypoint
entrypoint?: string | WorkerModuleThe entrypoint module that will be executed. May be either a path string (e.g. "./src/index.ts") or a module namespace imported with the cf-worker import attribute.
compatibilityDate: "<COMPATIBILITY_DATE>", (compatibilityDate reference)
compatibilityDateRequiredLink to compatibilityDate
compatibilityDate: stringA date in the form yyyy-mm-dd, which will be used to determine which version of the Workers runtime is used. More details at https://developers.cloudflare.com/workers/configuration/compatibility-dates
exports: { (exports reference)
exportsOptionalLink to exports
exports?: Record<string, Export>Configuration for named exports declared by the Worker. Each entry's key is the exported class name; the value configures the export. - Construct entries with exports.durableObject(...). - Declares Durable Object classes exported from this Worker. For more information about Durable Objects, see the documentation at https://developers.cloudflare.com/workers/learning/using-durable-objects. For reference, see https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects. - Construct entries with exports.workflow(...). - Declares Workflows defined by this Worker. For more information about Workflows, see the documentation at https://developers.cloudflare.com/workflows/.
Counter: exports.durableObject({ (durableObject reference)
durableObjectBuilderLink to durableObject
durableObject(options: DurableObjectTransferredExportOptions): DurableObjectTransferredExport;Transfer ownership of a Durable Object namespace to another Worker in the same account.
state: "transferred", (state reference)
transferredTo: "destination-worker", (transferredTo reference)
transferredToRequiredLink to transferredTo
transferredTo: stringThe destination Worker. Must reference a Worker in the same account.
Lifecycle changes take effect when a version is deployed, not when it is
uploaded. Deploy an export-changing version to 100% of traffic before you split
traffic with other versions. The platform rejects split deployments whose
versions disagree about exports.
Define a Container once. Reference it from a Durable Object export and add it to
the top-level containers array.
Select a highlighted line to show its type and description below it.
const imageProcessor = defineContainer({ (defineContainer reference)
defineContainerFunctionLink to defineContainer
defineContainer<T extends ConfigInput<ContainerConfig>>(config: T): T;Defines a Container application that you can list in containers in defineConfig() or attach to a Durable Object export with its container option.
export default defineConfig({ (defineConfig reference)
defineConfigFunctionLink to defineConfig
defineConfig<T extends ConfigInput<CloudflareConfig>>(config: T): T;Defines the default export of cloudflare.config.ts. Pass a configuration object, a promise that resolves to one, or a function that receives the config context (isPreview and mode) and returns either.
worker: { (worker reference)
workerOptionalLink to worker
worker?: ConfigInput<WorkerConfig>The Worker defined by this configuration.
name: "image-worker", (name reference)
entrypoint, (entrypoint reference)
entrypointOptionalLink to entrypoint
entrypoint?: string | WorkerModuleThe entrypoint module that will be executed. May be either a path string (e.g. "./src/index.ts") or a module namespace imported with the cf-worker import attribute.
compatibilityDate: "<COMPATIBILITY_DATE>", (compatibilityDate reference)
compatibilityDateRequiredLink to compatibilityDate
compatibilityDate: stringA date in the form yyyy-mm-dd, which will be used to determine which version of the Workers runtime is used. More details at https://developers.cloudflare.com/workers/configuration/compatibility-dates
exports: { (exports reference)
exportsOptionalLink to exports
exports?: Record<string, Export>Configuration for named exports declared by the Worker. Each entry's key is the exported class name; the value configures the export. - Construct entries with exports.durableObject(...). - Declares Durable Object classes exported from this Worker. For more information about Durable Objects, see the documentation at https://developers.cloudflare.com/workers/learning/using-durable-objects. For reference, see https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects. - Construct entries with exports.workflow(...). - Declares Workflows defined by this Worker. For more information about Workflows, see the documentation at https://developers.cloudflare.com/workflows/.
ImageProcessor: exports.durableObject({ (durableObject reference)
durableObjectBuilderLink to durableObject
durableObject<TContainer extends ContainerDefinition | undefined = undefined>(options: DurableObjectCreatedExportOptions<TContainer>): DurableObjectCreatedExport<TContainer>;Declares a Durable Object class defined by this Worker. For more information about Durable Objects, see the documentation at https://developers.cloudflare.com/workers/learning/using-durable-objects For reference, see https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects
storage: "sqlite", (storage reference)
storageRequiredLink to storage
storage: "sqlite" | "legacy-kv"Selects the SQLite-backed storage engine (recommended for new classes). Selects the legacy key-value storage engine.
container: imageProcessor, (container reference)
containerOptionalLink to container
container?: TContainerAttach a Container application to this Durable Object by config reference.
env: { (env reference)
envOptionalLink to env
env?: Record<string, Binding>Bindings exposed on the Worker's env object. Construct entries with bindings.kv(...), bindings.r2(...), etc.
IMAGE_PROCESSOR: bindings.durableObject({ (durableObject reference)
durableObjectBuilderLink to durableObject
durableObject<TWorker$1 extends WorkerReference, TExportName$1 extends DurableObjectExportName<TWorker$1>>(options: DurableObjectBindingOptions<TWorker$1, TExportName$1>): DurableObjectBinding<TWorker$1, TExportName$1>;Binding to a Durable Object class. worker is the name or config of the Worker that defines the class; exportName is the exported class name. For reference, see https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects
worker: "image-worker", (worker reference)
workerRequiredLink to worker
worker: TWorker$1The name or config of the Worker that defines the Durable Object class.
exportName: "ImageProcessor", (exportName reference)
exportNameRequiredLink to exportName
exportName: TExportName$1The exported class name of the Durable Object.
containers: [imageProcessor], (containers reference)
containersOptionalLink to containers
containers?: ConfigInput<ContainerConfig>[]Container applications defined by this configuration.
Container names must be unique. Each Container can be linked to only one Durable Object export.
cf deploy applies supported Container application changes.
cf workers versions create prepares images for Durable Object-managed
Containers, but it does not apply Container applications.
Set accountId and complianceRegion at the top level of the default export.
Supported compliance regions are public and fedramp-high.
CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_COMPLIANCE_REGION take priority over
these values. When neither the environment nor the configuration sets an
account, cf uses the account it saved on an earlier command, or resolves one
from your credentials. For the full order, refer to
Select an account.
cf searches from the current directory toward the filesystem root and uses
the nearest cloudflare.config.ts file.
When an API command reads account defaults, cf executes the module and
resolves the default export. If the default export is a function, cf calls it
with isPreview: false and the mode passed with --mode. Without --mode, the
mode is undefined, while a Vite build of the same project uses production.
cf deploy, cf workers versions create, and cf workers triggers deploy
resolve the account the same way. Without --mode, they evaluate the
configuration with an undefined mode, even when the Vite build used
production. If accountId depends on the mode, pass --mode explicitly to
every command.
API commands do not evaluate nested worker or containers factories, and they
do not validate Worker fields. Syntax errors, import errors, and top-level
runtime errors in the module still break them.
Pass --mode <NAME>, or -m <NAME>, to evaluate function-form configuration
for a named mode. Project commands also pass the mode to the build:
cf build --mode staging
cf deploy --mode stagingWhen you omit --mode, the default depends on the tool that evaluates the
configuration:
| Command | Default mode |
|---|---|
cf dev with the Cloudflare Vite plugin |
development |
cf build, cf deploy, and other commands that build with Vite |
production |
| Commands that build with Wrangler | undefined |
API commands, such as cf d1 list |
undefined |
When cf runs a framework's own command, only Vite and Astro accept --mode.
For other frameworks, the command stops with an error that says the detected
command does not currently support --mode.
Build Output records the mode in its root config.json. To deploy an existing
build with --prebuilt, pass the recorded mode. For the rule and examples,
refer to Deploy a prebuilt build.