Migrate a Wrangler project

Last updated Oct 20, 2026 cf migrate converts a Wrangler configuration file to cloudflare.config.ts and adds cf to your project. It handles most of the conversion, then lists the items that you finish by hand. This page covers the whole migration: preview, run, resolve follow-up items, finish the project, validate, and deploy.

Beta

cf is in beta. Commands, configuration, and Build Output can change before the stable release.

The examples on this page migrate orders-api, a Worker with a D1 database, a queue, a cron trigger, a route, and a Durable Object:

{
    "name": "orders-api",
    "main": "src/index.ts",
    "upload_source_maps": true,
    "account_id": "<ACCOUNT_ID>",
    "compatibility_date": "2026-08-24",
    "compatibility_flags": ["nodejs_compat"],
    "vars": {
        "ENVIRONMENT": "production",
    },
    "d1_databases": [
        {
            "binding": "DB",
            "database_name": "orders-db",
            "database_id": "<DATABASE_ID>",
        },
    ],
    "queues": {
        "producers": [{ "binding": "JOBS", "queue": "orders-jobs" }],
        "consumers": [{ "queue": "orders-jobs", "max_batch_size": 10 }],
    },
    "routes": [{ "pattern": "api.example.com/*", "zone_name": "example.com" }],
    "triggers": {
        "crons": ["0 * * * *"],
    },
    "durable_objects": {
        "bindings": [{ "name": "COUNTERS", "class_name": "Counter" }],
    },
    "migrations": [{ "tag": "v1", "new_sqlite_classes": ["Counter"] }],
}
name = "orders-api"
main = "src/index.ts"
upload_source_maps = true
account_id = "<ACCOUNT_ID>"
compatibility_date = "2026-08-24"
compatibility_flags = [ "nodejs_compat" ]

[vars]
ENVIRONMENT = "production"

[[d1_databases]]
binding = "DB"
database_name = "orders-db"
database_id = "<DATABASE_ID>"

[[queues.producers]]
binding = "JOBS"
queue = "orders-jobs"

[[queues.consumers]]
queue = "orders-jobs"
max_batch_size = 10

[[routes]]
pattern = "api.example.com/*"
zone_name = "example.com"

[triggers]
crons = [ "0 * * * *" ]

[[durable_objects.bindings]]
name = "COUNTERS"
class_name = "Counter"

[[migrations]]
tag = "v1"
new_sqlite_classes = [ "Counter" ]

Before you begin

  • Install cf and meet its requirements. You do not need to sign in until you deploy.
  • Commit or stash every change, including untracked files. cf migrate does not write files when git status reports changes anywhere in the repository. Files that .gitignore excludes do not count.
  • Install the project's dependencies. With the Wrangler bundler, the Worker's package needs Wrangler 4.136.0 or later installed. cf migrate uses it to write wrangler.config.ts, and cf dev, cf build, and cf deploy run it.
  • Do not run cf dev, cf build, or cf deploy in the project first. In an unmigrated project they write their own configuration or fail.

Preview the migration

In the directory that contains the Wrangler configuration file, run:

cf migrate --dry-run

Without a path, cf migrate looks for exactly one wrangler.json, wrangler.jsonc, or wrangler.toml file in the current directory. For a configuration file elsewhere, such as a package in a monorepo, pass its path:

cf migrate packages/api/wrangler.jsonc --dry-run

cf migrate writes its files next to the configuration file.

The dry run lists the files it would change and the follow-up items. It does not show file contents. For orders-api, it prints:

Using the Wrangler bundler because @cloudflare/vite-plugin is not declared. Pass --bundler vite to override.
Would update 4 file(s):
├─ cloudflare.config.ts
├─ wrangler.config.ts
├─ package.json
└─ package-lock.json

Follow-up work:
├─ [required] durable_objects.bindings.0: Durable Object bindings require manual review after migration.
│  └─ https://developers.cloudflare.com/workers/runtime-apis/context/#exports
└─ [required] migrations: Wrangler Durable Object migrations are unsupported. Replace them with an exports lifecycle declaration, for example `exports: { MyDurableObject: exports.durableObject({ storage: "sqlite" }) }`.
   └─ https://developers.cloudflare.com/workers/runtime-apis/context/#exports

⚠ Migration requires follow-up work.

Like a real run, the dry run exits with status 1 while [required] items remain. It does not check whether the Git worktree is clean.

Choose a bundler

cf migrate chooses a bundler for the migrated project from the package.json file beside the Wrangler configuration file:

Bundler Chosen when Builds with Build settings live in
Vite @cloudflare/vite-plugin is declared Vite and the Cloudflare Vite plugin vite.config.ts
Wrangler @cloudflare/vite-plugin is not declared Wrangler, installed in the project wrangler.config.ts, which cf migrate writes

When you do not pass --bundler, the first line of output explains the choice, as in the orders-api preview. To override the choice, pass --bundler vite or --bundler wrangler.

cf migrate does not install Vite or create vite.config.ts. To move a project that does not use Vite yet to the Vite bundler, pass --bundler vite, then install Vite and the Cloudflare Vite plugin beta that cf uses:

npmyarnpnpmbun

npm i -D vite @cloudflare/vite-plugin@beta
yarn add -D vite @cloudflare/vite-plugin@beta
pnpm add -D vite @cloudflare/vite-plugin@beta
bun add -d vite @cloudflare/vite-plugin@beta

Then create vite.config.ts:

vite.config.tsts

import { cloudflare } from "@cloudflare/vite-plugin";
import { defineConfig } from "vite";

export default defineConfig({
    plugins: [cloudflare()],
});

If the project already uses the Cloudflare Vite plugin, install @cloudflare/vite-plugin@beta in the same way. The beta reads cloudflare.config.ts and has no configPath option. Remove configPath if vite.config.ts passes it to cloudflare().

Run the migration

Run cf migrate with the same arguments as the dry run, without --dry-run:

cf migrate

cf migrate accepts these arguments:

Argument Description
[path] Path to the Wrangler configuration file. Defaults to the only wrangler.json, wrangler.jsonc, or wrangler.toml in the current directory.
--bundler vite or wrangler. Chosen from package.json when omitted.
--dry-run Lists the files that would change without writing them.
--force Runs even if the Git worktree is not clean. It does not bypass any other check.
--no-install Skips adding cf to the project.

Review what changed

Review the changes with git status and git diff. cf migrate changes these files:

File Change
cloudflare.config.ts Created next to the Wrangler configuration file
wrangler.config.ts Created with the Wrangler bundler only. It holds Wrangler build settings.
package.json and the lockfile Updated to add cf as a development dependency
The Wrangler configuration file Unchanged
Package scripts, vite.config.ts, .gitignore, tsconfig.json, and source Unchanged

The project needs its own cf dependency because cloudflare.config.ts imports from cf/config. cf migrate installs it with the package manager that the project uses, based on the packageManager field or the lockfile. With npm, the install also rewrites package.json with two-space indentation.

If the only package.json is in a parent directory, such as a workspace root, cf migrate does not change it. Install cf in the package that contains the Worker instead.

cf migrate never overwrites files. It stops if cloudflare.config.ts exists, or if wrangler.config.ts exists and you use the Wrangler bundler. --force does not change this.

Read the output

Each follow-up item has one of two levels:

  • [required]: you must resolve it before the project builds. While any required item remains, cf migrate exits with status 1. This does not mean that the migration failed.
  • [info]: context that needs no change.

cf migrate also writes each required item into cloudflare.config.ts as a TODO(@cloudflare) comment. When required items remain, it adds a throw statement at the top of the file. Until you delete that statement, cf dev, cf build, and cf deploy fail with this error:

Error: Migration incomplete. Resolve every cf migrate TODO in `cloudflare.config.ts`.

For orders-api, cf migrate generates this file:

cloudflare.config.tsts

import { bindings, defineConfig, triggers } from "cf/config";

/**
 * This migration needs manual work. Resolve every TODO in this file, then remove the error below.
 */
/**
 * TODO(@cloudflare): cf migrate: durable_objects.bindings.0: Durable Object bindings require manual review after migration.
 * @see https://developers.cloudflare.com/workers/runtime-apis/context/#exports
 */
/**
 * TODO(@cloudflare): cf migrate: migrations: Wrangler Durable Object migrations are unsupported. Replace them with an exports lifecycle declaration, for example `exports: { MyDurableObject: exports.durableObject({ storage: "sqlite" }) }`.
 * @see https://developers.cloudflare.com/workers/runtime-apis/context/#exports
 */
throw new Error("Migration incomplete. Resolve every cf migrate TODO in `cloudflare.config.ts`.");

export default defineConfig({
    accountId: "<ACCOUNT_ID>",
    worker: {
        name: "orders-api",
        compatibilityDate: "2026-08-24",
        compatibilityFlags: [
            "nodejs_compat",
        ],
        entrypoint: "src/index.ts",
        triggers: [
            triggers.fetch({
                pattern: "api.example.com/*",
                zone: "example.com",
            }),
            triggers.scheduled({
                schedule: "0 * * * *",
            }),
            triggers.queue({
                maxBatchSize: 10,
                name: "orders-jobs",
            }),
        ],
        env: {
            ENVIRONMENT: bindings.text("production"),
            DB: bindings.d1({
                name: "orders-db",
                id: "<DATABASE_ID>",
            }),
            JOBS: bindings.queue({
                name: "orders-jobs",
            }),
            COUNTERS: bindings.durableObject({
                worker: "orders-api",
                exportName: "Counter",
            }),
        },
        /**
         * TODO(@cloudflare): cf migrate: Durable Object bindings require manual review after migration.
         * @see https://developers.cloudflare.com/workers/runtime-apis/context/#exports
         */
        /**
         * TODO(@cloudflare): cf migrate: Wrangler Durable Object migrations are unsupported. Replace them with an exports lifecycle declaration, for example `exports: { MyDurableObject: exports.durableObject({ storage: "sqlite" }) }`.
         * @see https://developers.cloudflare.com/workers/runtime-apis/context/#exports
         */
    },
});

Some items link to Wrangler or Workers runtime documentation. The next section describes how to resolve each item for cf. When you have resolved every item, delete the TODO(@cloudflare) comments, the comment that starts with This migration needs manual work, and the throw statement.

Resolve follow-up items

Durable Objects

A project with Durable Objects always has required items: one for each Durable Object binding and one for the migrations history. cf migrate converts each binding, but it does not convert migrations.

  1. Import exports from cf/config. Under worker, add an exports entry for each Durable Object class that is live today. Match the storage that the class already uses: "sqlite" for classes created with new_sqlite_classes, and "legacy-kv" for classes created with new_classes.
   exports: {
    Counter: exports.durableObject({ storage: "sqlite" }),
   },
   ```

2. Review each generated binding. In `bindings.durableObject({ worker, exportName })`, `worker` is the name of the Worker that defines the class and `exportName` is the class name.
3. Delete the TODO comments for these items.

Do not copy renames or deletions that have already been applied. For classes that you still need to rename, delete, or transfer, refer to [Convert Durable Object migrations](https://developers.cloudflare.com/cf/wrangler/reference/#convert-durable-object-migrations).

### Environments

`cf migrate` converts each `env.<NAME>` block into a `case` of a `switch (ctx.mode)` statement. Each case returns a complete configuration. It follows Wrangler's inheritance rules: bindings, `vars`, and secrets from the top level are not copied into environments. An environment without its own `name` gets `<NAME>-<ENVIRONMENT>`. The generated configuration has this shape:

*cloudflare.config.tsts*

```ts
export default defineConfig((ctx) => {
    switch (ctx.mode) {
        case "staging": {
            return {
                worker: {
                    name: "orders-api-staging",
                    // ...
                },
            };
        }
        default: {
            return {
                worker: {
                    name: "orders-api",
                    // ...
                },
            };
        }
    }
});

Replace --env <NAME> with --mode <NAME>:

cf build --mode staging
cf deploy --mode staging

A required item that applies to the top-level configuration appears again for each environment that inherits it.

Without --mode, the Wrangler bundler uses the default branch. The Vite bundler uses the development mode for cf dev and production for cf build and cf deploy. With the Vite bundler, an environment named production or development would be selected without --mode, so cf migrate marks it as required. Rename that case, for example to "prod", and pass the new name with --mode.

For mode defaults across all commands, refer to Convert environments to modes.

Build settings

Wrangler build fields, such as build, minify, alias, and assets.directory, do not belong in cloudflare.config.ts.

With the Wrangler bundler, cf migrate moves them to wrangler.config.ts with camelCase keys, and no follow-up item is needed. For example:

wrangler.config.tsts

```ts import { defineWranglerConfig } from "wrangler/experimental-config";