denoflare icon indicating copy to clipboard operation
denoflare copied to clipboard

Documentation on architecture

Open mb21 opened this issue 3 months ago • 2 comments

Denoflare seems awesome. But how does it do its magic? Does it polyfill the whole Deno namespace with wasm, or?

How does Denoflare do bundling? (edit: hidden in the "New in v0.7.0+" box I see it's using deno bundler now.) Wrangler just uses esbuild, and while they say "Disabling bundling is not recommended in most scenarios.", they don't say why it's needed. Is the file system abstraction on their edge so slow? Deno Deploy doesn't say whether they bundle. Is it not needed for their environment? Or do they do it transparently, rewriting error messages with source maps etc?

I have a Deno app and am wondering what's the best way to deploy it on Cloudflare. I see the following options:

  • use Deno Deploy, where presumably everything is optimized, but I'm not in the Cloudflare ecosystem
  • use Denoflare. But what exactly happens when I do Deno.readFile within Denoflare? what are the performance characteristics I should expect?
  • Cloudflare supports node's filesystem api as well now: so I could also change the few places where I read a file to fs.readFile().

I couldn't find a page in the Denoflare docs that let me evaluate things according to these criteria. Thanks.

mb21 avatar Sep 24 '25 07:09 mb21

Not sure if you read the whole thing, Denoflare bundles into a single Cloudflare worker script using esbuild on 2.x which has been current for some time. Deno 1.x is now pretty old, but Denoflare has been around for a long time and also works there.

Under the hood, it uses deno bundle on Deno 1.x and esbuild + esbuild-deno-loader on Deno 2.x.

Denoflare is designed to make Cloudflare workers easy to write/test/dev in Deno. It is not meant to port or polyfill anything Deno-specific. The Cloudflare workers runtime is not Deno, it's not even NodeJS, but something simpler in a way, and much more complicated in a way.

As such, nothing in the Deno namespace will work on Cloudflare when pushed via denoflare push.

Anything filesystem-like in your architecture needs to be rethought when running on Cloudflare's stack, it's really best to understand the Cloudflare platform before getting started.

johnspurlock-skymethod avatar Sep 25 '25 16:09 johnspurlock-skymethod

Thanks for the reply! That clears things up.

Yes, I later saw that sentence, it's somewhat hidden in the "New in v0.7.0+" box, which I skipped on first read, because I'm new to the whole project. Perhaps move that out to a paragraph below, and also say the Deno namespace is left unpopulated? Just to make things clearer for newcomers.

Right, there is of course no real filesystem, certainly not one you can write to. Put you can import files as text or bytestring, and now you can even use fs.readFile with the nodejs_compat compatibility option (blog post). But Cloudflare always encourage you to bundle things into ideally a single file instead of doing that, and was wondering how slows things really would be if you wouldn't bundle, or read more files like that. But I suppose I might have to do some benchmarking myself.

mb21 avatar Sep 26 '25 15:09 mb21