Why this exists
You'd think rendering Svelte on a Cloudflare Worker would be easy. It is โ but only if you compile at build time.
The codegen wall
Cloudflare Workers run on a V8 isolate with code generation from strings disabled. eval, new Function, and friends all throw at runtime:
EvalError: Code generation from strings disallowed for this context That's a security feature, not a bug. It rules out a popular pattern: compile Svelte source on the edge with svelte/compiler, evaluate the compiled output via new Function, render via svelte/server.
Several public projects appear to do this. They don't. Look at the request flow โ anything claiming "edge SSR via runtime compile" on Workers is either skipping SSR (client-only mount) or quietly returning a 500 in production.
The fix
Move the compile to build time. esbuild-svelte in server mode produces an ES module that imports svelte/internal/server normally. Workers can import ES modules. Workers can call functions. There's no string to evaluate.
At request time:
- Import the SSR module (built in advance).
- Call
render(component, { props })fromsvelte/server. - Wrap the HTML in a shell with an inline script that hydrates from the pre-built client bundle.
What you lose
- You can't accept Svelte source as a string at runtime. The source must be a real
.sveltefile the build sees. - The bundle ships pre-compiled Svelte runtime. ~45 KB minified for a simple component.
What you keep
- Real Svelte 5:
$state,$props,$effect, snippets, etc. - Real SSR โ first paint is HTML, indexable, fast.
- Real hydration โ events, reactivity, all of it.
- Hono's router on top.
Why not SvelteKit?
SvelteKit is a full framework โ file-system router, layouts, load functions, an opinionated build, a Vite-based pipeline, an adapter per host. If you want all that, use it. @sveltejs/adapter-cloudflare is great.
This is for a different shape: "I'm already building a Hono Worker. I want components."
Why not just Hono JSX?
Hono JSX is excellent for SSR โ but no client-side reactivity. If your page is interactive, Svelte 5's signal-based runtime is genuinely small and pleasant. Use Hono JSX when the page is read-only.