utils icon indicating copy to clipboard operation
utils copied to clipboard

Package is incompatible with Astro's Cloudflare adapter

Open jrencz opened this issue 1 year ago • 3 comments

Hi,

This is not necessarily a "bug", but that's the only issue template available.

I tried combining this package with https://docs.astro.build/en/guides/integrations-guide/cloudflare/ but with no success. It, and its dependencies don't follow the requirement to

have all node internals' specifiers prefixed with node:.

Here's a list of those that might be prefixed and may get this closer to working in workers environment:

  • assert
  • path
  • crypto
  • util
  • buffer
  • stream

But I also see those:

  • fs
  • fs/promises
  • os

and those don't have support in Cloudflare (see https://developers.cloudflare.com/workers/runtime-apis/nodejs#nodejs-api-polyfills)

There's also a dependency on https://www.npmjs.com/package/snappy and it's a hard no-go for Workers runtime, because it's written in Rust and is published as NAPI node extension.

Question: is making this package compatible with workers (or extracting its subset which might at some point become) is considered "in scope"?

jrencz avatar Sep 22 '24 11:09 jrencz

Hi @jrencz, sorry for the delay (did not get GitHub notification, need to figure this out). For your question, I am afraid not, this package does a lot of the hard lifting and depends on the context.

The fs/fs-promises is required for file uploads and snappy is required for the context for ASP.NET like experience.

It is possible to create a subset of this package without file upload and replace snappy with something else, but for now it is the best I found (I term of speed and compression)

Could you explain more what is your use case?

ido-pluto avatar Feb 26 '25 12:02 ido-pluto

Hi, thanks for the answer.

I'm primarily interested in JWT session and CSRF protection - those things seem like they could live without a link to filesystem.

I try to deploy it to Cloudflare Pages

Maybe a way to go would be to extract a smaller package with just workers runtime compatible stuff?

https://developers.cloudflare.com/workers/runtime-apis/

jrencz avatar Feb 26 '25 12:02 jrencz

I'll investigate that. As you mentioned, only "bigFileUpload" requires the fs and os modules. However, incorporating a high-speed, highly-efficient compression library (such as snappy) might be more challenging

ido-pluto avatar Mar 05 '25 16:03 ido-pluto