sveltejs / sveltejs/kit

Allow custom worker script when deploying to Cloudflare

Open
#13,692 18 comments 35 reactions 1 assignee View on GitHub

@teemingc is already working on this.

Since Jul 16, 2026.

  • #13207 by @thomasfosterau — closed without merging
  • #13739 by @thomasfosterau — closed without merging
  • #15574 by @teemingc — closed without merging
  • #15627 by @teemingc — closed without merging
pkg:adapter-cloudflare
Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the problem

When deploying to Cloudflare there's no way to customize the worker. This means no Durable Objects, no RPC methods, no CRON jobs, just the fetch() handler.

Describe the proposed solution

Currently when building with the adapter-cloudflare the entry Worker file gets generated at .svelte-kit/cloudflare/_worker.js. At its core it just exports the fetch handler for the Worker.

// other stuff...

var worker_default = {
  async fetch(req, env, context) {
    // request handling...
  }
};
export {
  worker_default as default
};

Other frameworks like React Router create a workers folder in the root directory of the project containing app.ts—the worker script. It looks like this:

import { createRequestHandler } from "react-router";

declare module "react-router" {
  export interface AppLoadContext {
    cloudflare: {
      env: Env;
      ctx: ExecutionContext;
    };
  }
}

const requestHandler = createRequestHandler(
  () => import("virtual:react-router/server-build"),
  import.meta.env.MODE
);

export default {
  async fetch(request, env, ctx) {
    return requestHandler(request, {
      cloudflare: { env, ctx },
    });
  },
} satisfies ExportedHandler<Env>;

React Router basically provides a handler you can use in your worker in the fetch(). Why wouldn't SvelteKit be able to provide something similar?

Alternatives considered

No response

Importance

would make my life easier

Additional Information

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.