Migrate a Wrangler project·续
export default defineWranglerConfig({ alias: { lodash: "lodash-es", }, minify: true, uploadSourceMaps: true, build: { command: "npm run build:css", }, dev: { port: 8788, }, types: { generate: false, }, assetsDirectory: "./public", });
`wrangler.config.ts` is experimental and can change during the beta.
With the Vite bundler, `cf migrate` lists these fields in a required item and does not move them. Move each setting to its Vite equivalent in `vite.config.ts`, such as `alias` to `resolve.alias`. For every field, refer to [Build settings](https://developers.cloudflare.com/cf/wrangler/reference/#build-settings).
A custom `build` command does not carry over to the Vite bundler. `cf build` runs Vite directly, so run the command yourself first, for example `npm run build:css && cf build`.
### Source maps
With the Vite bundler, `cf migrate` does not move `upload_source_maps` and reports it as a follow-up item. `cf deploy` uploads every source map in the build output, and the Cloudflare Vite plugin generates source maps for the Worker's Vite environment by default from version 1.64.0. You do not need to replace `upload_source_maps: true`.
To stop uploading source maps, set `build.sourcemap` to `false` for the Worker's Vite environment. By default, the Cloudflare Vite plugin beta names the Worker's environment `ssr`:
*vite.config.tsts*
```ts
import { cloudflare } from "@cloudflare/vite-plugin";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [cloudflare()],
environments: {
ssr: {
build: {
sourcemap: false,
},
},
},
});
On earlier versions of the Cloudflare Vite plugin, set build.sourcemap to true to generate source maps.
How cf migrate reports source maps can change during the beta.
D1 migrations
cf migrate does not convert the migrations_dir, migrations_pattern, or migrations_table fields of a D1 binding. Pass them to cf d1 migrations apply instead:
| Wrangler field | cf d1 migrations apply option |
|---|---|
migrations_dir |
--dir, which defaults to ./migrations |
migrations_pattern |
--pattern |
migrations_table |
--table, which defaults to d1_migrations |
For example:
cf d1 migrations apply <DATABASE_ID> --dir db/migrations
cf d1 migrations apply takes the database ID. Unlike Wrangler, it applies migrations to the remote database unless you add --local.
Other required items
Resolve the remaining items as follows, then delete each TODO comment:
| Item | What to do |
|---|---|
Preview resources: preview_id, preview_bucket_name, preview_database_id |
cloudflare.config.ts has no preview resource fields. During cf dev, bindings use local resources unless you set dev: { remote: true } on the binding. |
A route that uses zone_id |
cf migrate copies the zone ID into the zone option of triggers.fetch(), which accepts a zone name or a zone ID. Confirm the value. |
| A service binding to a legacy service environment | cf migrate rewrites the target to <SERVICE>-<ENVIRONMENT>. Confirm that this is the Worker to bind to. |
Workers Sites (site) |
Not supported. Move the site to Workers Static Assets. |
previews |
Converted to a branch on ctx.isPreview. Review the branch. For more information, refer to Deploy a preview. |
A missing name or compatibility_date |
Replaced with the placeholders "TODO" and "YYYY-MM-DD". Set real values. |
Unsupported or unknown fields, such as keep_vars |
Remove them, or find an equivalent in the configuration reference. |
Installing cf |
Appears with --no-install, after a failed install, or when no package.json is beside the configuration file. Install cf in the Worker's package. |
To install cf as a development dependency, run:
npmyarnpnpmbun
npm i -D cf
yarn add -D cf
pnpm add -D cf
bun add -d cf
Workflows and Containers
cf migrate does not convert Workflow bindings or Containers configuration. It reports both as required items. Add them to cloudflare.config.ts by hand:
- For a Workflow, declare the class with
exports.workflow({ name })in the Worker that defines it. Bind to it withbindings.workflow({ name, worker, exportName }). Refer to Declare exports. - For a Container, define it with
defineContainer(), add it to the top-levelcontainersarray, and reference it from anexports.durableObject({ storage: "sqlite", container })entry. Refer to Attach a Container.
Then delete the TODO comment for each item.
Secrets
cf migrate never reads secret files. It lists any .dev.vars or .env files that it finds as an [info] item. cf dev still loads .dev.vars for local development.
Entries in secrets.required become bindings.secret() values. Declare any other secret that the Worker reads the same way:
env: {
API_TOKEN: bindings.secret(),
},
To upload secrets with a new version, pass --secrets-file <PATH> to cf deploy or cf workers versions create. The file can be JSON or .env format.
Finish the project
cf migrate leaves the rest of the project to you:
- Replace Wrangler commands in the
package.jsonscripts. Wrangler commands read the Wrangler configuration file and ignorecloudflare.config.ts.
package.jsonjson
{
"scripts": {
"dev": "cf dev",
"build": "cf build",
"deploy": "cf deploy"
}
}
```
`cf build` runs Vite or Wrangler directly, not your `build` script. To run extra steps, chain them yourself, for example `tsc -b && cf build`.
2. Add `.cloudflare/` to `.gitignore`. The directory holds Build Output, generated types, and other files that `cf` generates.
3. Set `"type": "module"` in `package.json`. Without it, Node.js prints a `MODULE_TYPELESS_PACKAGE_JSON` warning each time `cf` loads `cloudflare.config.ts`.
4. Generate types:
- With the Vite bundler, `cf dev` and `cf build` write `.cloudflare/types/index.d.ts`.
- With the Wrangler bundler, `cf migrate` sets `types: { generate: false }` in `wrangler.config.ts`. Change it to `true`, or run `cf workers types`.
Then add the generated types to `tsconfig.json`:
*tsconfig.jsonjson*
```json
{
"include": ["src", "cloudflare.config.ts", ".cloudflare/types"]
}
```
5. (Optional) Replace the string `entrypoint` with an import that uses the `cf-worker` attribute:
*cloudflare.config.tsts*
```ts
import * as entrypoint from "./src/index.ts" with { type: "cf-worker" };
```
Under `worker`, replace `entrypoint: "src/index.ts"` with `entrypoint`. With a string path, `Env` binding types are still inferred, but the types of your Worker module exports are not. To type-check a `.ts` import path, set `allowImportingTsExtensions` in `tsconfig.json`.
For a finished version of `orders-api`, refer to [Complete example](https://developers.cloudflare.com/cf/wrangler/reference/#complete-example).
## Validate the project
Start the project locally with `cf dev` and check that it responds. Then stop the development server, build the project, and run a dry-run deployment:
```sh
cf build
cf deploy --dry-run
None of these commands need you to sign in. cf deploy --dry-run builds the project, prints the bindings it would deploy, and uploads nothing.
If the project has environments, also validate each mode:
cf build --mode staging
cf deploy --dry-run --mode staging
Deploy
Sign in, then deploy:
cf auth login
cf deploy
cf deploy builds the project, uploads a new Worker Version, and deploys it. For deployment options, refer to Develop, build, and deploy. To deploy from CI, refer to Use cf in CI.
Remove the Wrangler configuration
Once cloudflare.config.ts exists, cf ignores the Wrangler configuration file. Delete the Wrangler file after you deploy with cf and your scripts and CI use cf.
Wrangler does not read cloudflare.config.ts. If you still run Wrangler commands in the project, such as wrangler tail, keep the Wrangler configuration file until you no longer need them.
Troubleshooting
No Wrangler configuration found
No Wrangler config found in <DIRECTORY>. Pass its path to cf migrate.
Run cf migrate in the directory that contains the Wrangler configuration file, or pass the file path. If the directory contains more than one Wrangler configuration file, cf migrate reports Multiple Wrangler configs found in <DIRECTORY>. Pass the exact path.
Git worktree is not clean
Git worktree is not clean. Commit or stash your changes before running a codemod, or rerun with `--force` to bypass this safety check.
Commit or stash every change, including untracked files, then run the migration again.
cloudflare.config.ts already exists
Cannot migrate because <PATH>/cloudflare.config.ts already exists. Inspect and finish the existing migration; it will not be overwritten. Automated agents should read its TODOs and ask the user about unresolved choices.
If an earlier cf migrate run created the file, finish that migration. If cf dev, cf build, or cf deploy created it, undo their changes as described in Run project commands only after you migrate, then run cf migrate.
Wrangler is missing or too old
With the Wrangler bundler, cf migrate needs a local Wrangler installation, even for a dry run. Without one, it reports:
Generating wrangler.config.ts requires wrangler 4.100.0 or newer because earlier versions do not export wrangler/experimental-config. No local Wrangler installation was found. Update Wrangler and retry the migration.
After the migration, cf dev, cf build, and cf deploy need Wrangler 4.136.0 or later. With an older version, their error includes:
cf requires wrangler@4.136.0 or newer for cf dev, cf build, cf deploy, and cf previews deploy.
Install the project's dependencies or update Wrangler, then run the command again.
Migration incomplete
Error: Migration incomplete. Resolve every cf migrate TODO in `cloudflare.config.ts`.
Resolve the follow-up items, then delete the throw statement at the top of cloudflare.config.ts.
cloudflare.config.ts is required
Error: cloudflare.config.ts is required when --experimental-new-config is enabled.
cf dev, cf build, or cf deploy ran in a Wrangler project that you have not migrated. Run cf migrate.
Wrangler is not installed
wrangler is declared in <PATH>/package.json but is not installed.
Install the project's dependencies. cf looks for Wrangler only in the Worker package's own node_modules directory. In a monorepo, a copy hoisted to the workspace root does not count.
If package.json declares neither package, for example because you use a global Wrangler installation, the error starts with No Cloudflare dev-server is installed in this project. Add Wrangler as a development dependency, or install Vite and the Cloudflare Vite plugin as described in Choose a bundler.
Unknown command: migrate
A global cf runs the copy of cf installed in the project. If the project pins an older cf without cf migrate, update the project's cf dependency, or run the latest version once with npx cf@latest migrate.
Was this helpful?
YesNo
On this page
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/cf/wrangler/migrate/#page","headline":"Migrate a Wrangler project","description":"Convert a Wrangler project to cf with cf migrate, resolve the follow-up items, and deploy it with cloudflare.config.ts.","url":"https://developers.cloudflare.com/cf/wrangler/migrate/","inLanguage":"en","image":"https://developers.cloudflare.com/cf/wrangler/migrate/og.png?v=28973f624b22bb97","dateModified":"2026-10-20","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}
description: Find cf equivalents for Wrangler commands, and map Wrangler configuration, build settings, and environments to cf. title: Wrangler to cf reference image: https://developers.cloudflare.com/cf/wrangler/reference/og.png?v=89a02a5f88f20fa3
Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/cf/llms.txt
Use this file to discover all available pages before exploring further.
Docs