Skip to content
Esc

    Search bindings, commands, errors and guides.

    Getting started / Move from Deno Deploy

    Getting started

    Move from Deno Deploy

    Turn a Deno Deploy app into a Cloudflare Workers project that runs on Orange, or on Cloudflare.

    orange migrate deno turns a Deno Deploy app into a plain Cloudflare Workers project. Deno.serve, Deno.env, Deno.cron and Deno KV keep working, and the project has no Orange imports, so it also runs on Cloudflare.

    Quickstart

    You need Node.js 22 or later and pnpm. Your Deno app does not change: the command writes the project next to it.

    1. Write the Workers project

      Run the command in the folder that holds your app. It prints what moved and a checklist of what needs a change by hand.

      orange migrate deno notes
      ✓ Wrote a Workers project to notes-worker (10 files).
        ✓ main.ts:1 npm:mime@^4.0.0: Imports mime from package.json.
        ✓ main.ts:5 Deno.openKv: Stores its data in the DenoKvStore Durable Object.
        ✓ main.ts:6 Deno.env.get: Reads GREETING from the Worker's vars and secrets.
        ✓ main.ts:8 Deno.cron: Runs from the scheduled handler on "*/5 * * * *".
        ✓ main.ts:13 Deno.cron: Runs from the scheduled handler: "0 9 * * 1" (Deno) is "0 9 * * 2" in Cloudflare's weekday numbers.
        ✓ main.ts:37 Deno.KvU64: Is KvU64 from deno-compat/kv.ts.
        ✓ main.ts:59 Deno.serve: Runs as the Worker's fetch handler.
      
      ! 3 items need a change by hand:
        [ ] main.ts:17 kv.listenQueue: Deno KV queues and watch() do not run on Workers. Use Cloudflare Queues or a Durable Object alarm.
        [ ] main.ts:54 Deno.readTextFile: Read files that ship with the app from static assets or R2. node:fs also runs on Orange.
        [ ] deno.json:1 tasks: deno.json tasks (dev) did not move. package.json has wrangler dev and deploy scripts.
      
      Run it:
        cd notes-worker
        pnpm install
        orange dev
    2. Fix the checklist

      Change each listed line in notes-worker. Each item names the Workers API to use instead.

    3. Run it

      Put your environment variables in .dev.vars. .dev.vars.example lists the names your code reads.

      cd notes-worker
      cp .dev.vars.example .dev.vars
      pnpm install
      orange dev
    4. Deploy it

      Deploy to your Rivet cluster. See Deploy.

      orange deploy

    Run it on Cloudflare

    The project is a plain Workers project, so Wrangler deploys it as it is.

    pnpm wrangler deploy

    Update it after a change

    Change the Deno app, then run the command again. It rewrites the files it wrote, deletes the ones that no longer come from the app, and keeps files you added, such as .dev.vars. If you changed a file it wrote, it stops and lists the file: make that fix in the Deno app, or pass --force to overwrite it.

    orange migrate deno notes
    AI context What moves, what does not, Deno KV details, flags, exit codes, and errors

    Written for LLMs and coding agents: every edge case, measurement, and known deviation. You do not need it to use the feature.

    What moves

    In the Deno appIn the Workers project
    Deno.serve(handler), Deno.serve(options, handler), Deno.serve({ handler })The Worker’s fetch handler. The handler gets (request, info). info.remoteAddr.hostname is the cf-connecting-ip header, info.completed settles when the handler returns, and onError answers when the handler throws. The last call wins. Ports, hostnames and onListen do not apply.
    export default { fetch } in the entry module (deno serve)The Worker’s fetch handler, when the app calls no Deno.serve.
    Deno.env.get, has, set, delete, toObjectReads the Worker’s string vars and secrets through env from cloudflare:workers, so reads at module scope work. set and delete change only the running isolate.
    Deno.cron(name, "<cron>", [options], handler)A scheduled handler that runs every job whose schedule equals controller.cron, and the schedule in triggers.crons. backoffSchedule does not apply.
    Deno.openKv(path?)The DenoKvStore Durable Object, bound as DENO_KV, with a new_sqlite_classes migration. Each path is one object. No path is the object named default.
    Deno.KvU64KvU64 in deno-compat/kv.ts
    import.meta.maintrue in the entry module, false elsewhere
    npm:pkg@version/subpkg/sub, and "pkg": "version" in package.json
    jsr:@scope/name@version/sub@scope/name/sub, and "@scope/name": "npm:@jsr/scope__name@version" in package.json, with @jsr:registry=https://npm.jsr.io in .npmrc. This is JSR’s npm compatibility layer.
    npm:pkg or jsr:@scope/name with no versionThe version in deno.lock, else the version another import of the package names, else * with a checklist item. When deno.lock resolves it to the same release as an import with a version, both share that entry.
    Two versions of one package, such as npm:zod@3 and npm:zod@4One alias each, such as "zod-3": "npm:zod@3", and each import uses its alias
    imports in deno.json, or the file in importMapEach import resolves through the map as Deno does: an exact key, else the longest key that ends in /. A local path becomes a relative import. A path that starts with / is from the app’s folder. A node: built-in or a package name becomes that import.
    compilerOptions.jsx, jsxFactory, jsxFragmentFactory, jsxImportSource in deno.jsontsconfig.json, unless the app has one. "jsx": "precompile" becomes "react-jsx". A jsxImportSource package, with its subpath, goes in package.json.
    package.jsonMerged into the written package.json. Its dependencies win.

    Each file that uses the global Deno imports it from deno-compat/deno.ts, which holds only the APIs above. The import goes after a shebang line. Deno in type positions, such as Deno.Kv, does not change and is not reported. A file that declares or imports its own Deno, such as a parameter, keeps it in that scope.

    What does not move

    The command reports each of these with its file and line, and never drops code:

    In the Deno appWhat to do
    Other Deno.* APIs, such as Deno.readTextFile, Deno.upgradeWebSocket, Deno.CommandUse the Workers API that the report names. File APIs: static assets or R2. node:fs also runs on Orange, which runs stock Node.js.
    Deno.cron with an object schedule or a schedule that is not a string literalWrite the schedule as a cron string. At run time such a job logs an error and does not run.
    backoffSchedule in Deno.cron optionsWorkers do not retry a failed cron run. Retry inside the job.
    A Deno KV call at module scope, such as a top-level await kv.get()Move it into the Deno.serve handler or a Deno.cron job. Workers allow storage calls only inside a handler. At run time it fails with an error that says so.
    A Deno KV call that a Deno.cron job does not awaitAwait it. The scheduled handler ends when the job returns, so Cloudflare can drop the call.
    globalThis.Deno, self.Deno, window.DenoUse Deno. In a Worker these are undefined.
    Deno-only packages: a /deno adapter such as hono/deno or jsr:@hono/hono/deno, @std/fs, @std/http/file-server, @std/dotenvUse the package’s Workers adapter, and serve static files with Workers static assets (assets in wrangler.jsonc). These packages call the global Deno, which a Worker lacks, and fail with Deno is not defined.
    An npm: or jsr: import with no version that deno.lock does not listSet its version in package.json.
    The app’s own wrangler.jsonc, .dev.vars.example, or deno-compat/ filesThe command writes these files. Move what the app’s copy needs into the written one.
    kv.listenQueue(), kv.enqueue(), atomic().enqueue(), kv.watch()Use Cloudflare Queues or a Durable Object alarm. At run time listenQueue() logs an error, and the others fail with an error that names the replacement.
    new BroadcastChannel()Use a Durable Object.
    https:// importsAdd the package to package.json and import it by name. The report prints the URL without its credentials, query and fragment.
    An app with no Deno.serve call and no default exportFrameworks that call Deno.serve themselves, such as Fresh and Oak’s app.listen(), need Deno.serve(app.handler) or similar. Until then the Worker answers 500.
    deno.json tasks and keys the command does not knowpackage.json has dev and deploy scripts.
    Data in Deno KV on Deno DeployThe command moves code, not data. See Copy Deno KV data.

    The report finds every listenQueue() call, and watch() and enqueue() calls on a variable that holds await Deno.openKv() in any file, such as kv.atomic().enqueue(). A call through another name, such as a function parameter, is not reported, and fails at run time as above.

    Cron weekday numbers

    Cloudflare numbers weekdays from 1 (Sunday) to 7 (Saturday). Deno numbers them from 0 (Sunday) to 6, and 7 is also Sunday. The command moves each weekday in a schedule to Cloudflare’s number, both in the code and in triggers.crons, so a job runs on the same days: "0 9 * * 1" (Monday) becomes "0 9 * * 2", 1-5 becomes 2-6, and 5-7 becomes 1,6-7. Weekday names such as MON do not change.

    Deno KV on a Durable Object

    • Each database is one SQLite-backed Durable Object, so reads and atomic commits are strongly consistent, as on Deno Deploy. consistency: "eventual" reads the same data.
    • get, getMany, set, delete, list (with prefix, start, end, limit, reverse, cursor, batchSize), atomic() with check, set, delete, sum, min, max and mutate, versionstamps, expireIn, and close() work.
    • list() returns keys in Deno KV’s order. Keys are encoded as in denokv.
    • A versionstamp is 20 hex digits that grow with each commit to the database.
    • An entry stops reading as soon as its expireIn passes. Deno deletes it at some point after.
    • Values pass through Workers RPC and Durable Object storage, which use the structured clone algorithm. A KvU64 inside another value comes back as a plain object. A top-level KvU64 value comes back as a KvU64.
    • Cursors are Deno’s: the last key after the selector’s common prefix, in base64url. A cursor outside the selector’s range fails with cursor out of bounds, as in Deno. An iterator that ran out has the cursor "".
    • atomic() copies each key and value when it is queued, as Deno does.
    • A call at module scope, while the Worker’s modules load, fails with an error that says to move it into a handler.

    Copy Deno KV data

    The command does not copy data yet. Deno Deploy’s KV databases accept KV Connect from outside Deno Deploy: openKv from the @deno/kv npm package, with the database’s KV Connect URL and DENO_KV_ACCESS_TOKEN. A copy lists every entry there and writes it through the Worker’s DenoKvStore, with the app’s writes stopped. Deno Deploy shuts down in April 2027.

    Files

    FileWhat it is
    Your filesCopies, with the changes above. Files that .gitignore names, node_modules, .git, .open-orange, deno.json, deno.jsonc and deno.lock are not copied.
    wrangler.jsoncName from deno.json name without its scope, else the folder name. main is ./deno-compat/worker.ts, with nodejs_compat, crons and the KV binding.
    package.json, .npmrcDependencies from npm: and jsr: imports. .npmrc only for jsr:, with the app’s own .npmrc lines kept.
    .gitignoreThe app’s .gitignore, with .dev.vars* (but not .dev.vars.example), node_modules, .wrangler and .open-orange/* added
    .open-orange/migrate-deno.jsonEach file the command wrote, with its SHA-256. A later run reads it to tell its files from yours. .gitignore keeps it in Git.
    .dev.vars.exampleEach name that the code reads with Deno.env.get("NAME")
    deno-compat/worker.tsThe Worker’s entry. It imports your entry module and exports the Worker.
    deno-compat/deno.ts, deno-compat/kv.tsThe Deno APIs above and the DenoKvStore class

    The entry module is --entry, else deploy.entrypoint in deno.json, else the file that the start, serve or dev task runs, else the first of main.ts, main.tsx, main.js, server.ts, server.js, mod.ts, index.ts, index.js, src/main.ts, src/index.ts.

    Flags

    FlagMeaning
    [dir]The Deno app. Default: the current directory.
    --out <dir>Where to write the project. Default: <dir>-worker. It must be outside <dir>.
    --forceOverwrite, or delete, files in --out that changed since the last run
    --entry <file>The entry module, relative to <dir>
    --dry-runPrint the report and write nothing
    --jsonPrint { dryRun, files, items, out, removed, source }. removed lists the files a rerun deletes. Each item has api, file, line, column, note, and status (migrated or manual).
    --cwd <dir>Run as if started in <dir>

    Exit codes and errors

    CodeWhen
    0The project was written, or would be with --dry-run, also when the checklist has items
    1The app cannot move, and nothing was written: no entry module, a file that does not parse (Couldn't parse lib/broken.ts:1:18), invalid deno.json, package.json or deno.lock, a missing importMap file, or oxc-parser that does not load
    1The output is not safe to write, and nothing was written or deleted: --out is inside <dir> (also through a symlink), is a symlink, or is a file; --out holds files and no manifest; the manifest names a path outside --out; a path in --out is a symlink; a file the command did not write is where it would write, or where it needs a folder; or, without --force, a file it wrote has changed. The error lists the files.
    2An unknown flag, or more than one folder