Closed callmetwan closed 2 months ago
I wonder if this has something to do with Vite actually. Also, forgot to mention that I know Hono Sessions doesn't technically declare support for Cloudflare Pages they are very similar and was hoping for some help 😅
Looks like npm run dev
and npm run build
work for me. preview
doesn't, though. Could be a dependency such as iron-webcrypto
. Cloudflare Workers is one of the test targets and it works there. Needs more investigation.
I did a ton of debugging in between now and my initial post.
I’m reasonably confident the culprit is nanoid. Hono Sessions is using v4 which utilizes Node’s crypto APIs. In v5 the nanoid folks rewrote it to use the Web Crypto APIs.
I did have a test working that proved this but it involved importing Hono Sessions as a locally linked dependency and I broke something in the dependency management chain (shakes fist at yarn).
If you are able to test with v5 of nanoid (maybe the preview command that wasn’t working) that would be helpful! I’m not at all familiar with Deno or how the repository of dependencies are structured and I couldn’t get a local version running with v5; I’m sure it would be trivial for someone that knew what they were doing.
Thanks for taking a look!!
Thanks for investigating!
I have a branch called cloudflare-pages-compat
where I got rid of nanoid
altogether and just use web crypto randomUUID
. This is probably the way forward for better compatibility (and more performant, too). It shouldn't break existing sessions, it just won't create new ones based off of nanoid anymore.
Glad to do it! Thanks for swapping things out. I'll see if I can get this branch linked locally sometime this weekend
It worked!!
My project using Hono Sessions as published on npm:
My project using Hono sessions branch cloudflare-pages-compat
:
Excellent, thanks for trying it out! Glad it's working for you :smile: I'll test a little more then merge it in soon!
Merged the new changes and cut a new version!
Thanks you!!
Hello again!
I'm having an issue where Hono Sessions seems to require a crypto API that is unavailable when running in Cloudflare Pages
Repo to reproduce here: https://github.com/callmetwan/hono-sessions-crypto-error/blob/main/README.md
This is a brand new Hono project using the Hono create CLI. I added Hono Sessions (the only dependency aside from Hono) and I immediately get failures when running wrangler
Cloudflare supports some of the browser Crypto APIs so I'm surprised to see this. Is Iron depending on something not supported by Cloudflare?