vento icon indicating copy to clipboard operation
vento copied to clipboard

Feature request: Cloudflare Worker support

Open jvhellemond opened this issue 1 year ago • 5 comments

Hi, Are there any plans to make Vento compatible with Cloudflare Workers? I tried bundling the npm package (using esbuild), but ran into the dreaded Dynamic require of "node:fs" is not supported errors (et al.).

I know Vento is specifically a Deno project, but it would be awesome for my projects.

jvhellemond avatar Jun 22 '24 20:06 jvhellemond

Vento has an NPM distribution. Did you try it?

oscarotero avatar Jun 23 '24 09:06 oscarotero

Yes, but that results in errors like Dynamic require of "node:fs" is not supported. Cloudflare Workers is a bit like node, but not enough :|

jvhellemond avatar Jun 26 '24 15:06 jvhellemond

Do you know in which package/file this error occurs? I don't see any node:fs in Vento code (npm version). Maybe it's caused by a dependency.

oscarotero avatar Jun 26 '24 15:06 oscarotero

Yup, the dependency is @deno/shim-deno. The Cloudflare worker environment has no access to the filesystem, so node:fs is not available.

jvhellemond avatar Jul 07 '24 00:07 jvhellemond

If Cloudflare has no access to file system, you have to replace the default loader with other with support for Cloudflare API. The default loader is this. You can do something like this:

class CloudflareLoader {
  async load(file) {
    return {
      source: "File content here"
    }
  }

  resolve(from, file) {
    return "Resolved file";
  }
}


const env = vento({
  includes: new CloudflareLoader()
});

oscarotero avatar Jul 07 '24 11:07 oscarotero

Creating a Cloudflare workerd loader is the way to do this, so closing this issue ✌️

jvhellemond avatar Nov 06 '24 07:11 jvhellemond