Open ChristianJacobsen opened 1 month ago
I'm also having this issue without solution.
When nodejs_compat is enabled, the dependency that works with JWTs, jose
, breaks as it expects crypto.constants
, which is unsupported by Cloudflare's compat layer. See https://github.com/panva/jose/issues/659.
As for what is still depending on nodejs code when the compatibility layer is disabled, that's still an unknown to me.
@jackmawer, I don't know what happened to my other project, but it suddenly started working without upgrading Wrangler to a newer version... When I clone the reproduction repo I linked above I still get the error after install -> build -> wrangler pages dev
.
Obviously something fishy, but for now I'm happy it "works".
@jackmawer, I don't know what happened to my other project, but it suddenly started working without upgrading Wrangler to a newer version... When I clone the reproduction repo I linked above I still get the error after install -> build ->
wrangler pages dev
.Obviously something fishy, but for now I'm happy it "works".
Would you mind sharing your package lockfile? I wonder if it's an unusual dependency tree thing.
Although my understanding was that @auth/sveltekit
was all that was needed to be imported, it turns out that explicitly defining @auth/core
as a dependency seems to fix the building issues. Have not tried on your repro repo yet but it has worked on my local project.
Although my understanding was that
@auth/sveltekit
was all that was needed to be imported, it turns out that explicitly defining@auth/core
as a dependency seems to fix the building issues. Have not tried on your repro repo yet but it has worked on my local project.
Interesting... I did add @auth/core
as a dev-dependency because I wanted to augment some of the types.
I just tested with the repro-repo, and it does indeed fix all of the issues. Maybe Balázs has the answers we need as to why this is happening.
cc @balazsorban44 ☝️ same as we discussed yesterday
Environment
Reproduction URL
https://github.com/ChristianJacobsen/sveltekit-auth-cloudflare-node-crypto-reproduce
Describe the issue
When I build my SvelteKit project and launch it with
wrangler pages dev
, I am told thatThe requested module 'node:crypto' does not provide an export named 'constants'
. This is with thenodejs_compat
compatibility flag enabled. Without that, it complains that the module can't be found altogether.Now, I know that Cloudflare Workers doesn't provide the
constants
export of the Node.js Crypto API (https://developers.cloudflare.com/workers/runtime-apis/nodejs/crypto/), but as far as I can tell Auth.js isn't supposed to rely on anything but the browser's Web Crypto API. Is this not true for the Credentials provider I am using (for now)?From the Edge Compatibility docs it says:
I've assumed this far that everything in
@auth/sveltekit
is "core" to Auth.js, and I'm not using any external libraries in any portion of my auth code.How to reproduce
Run
pnpm run build
and thenpnpm run start
in the linked repo.Expected behavior
I expect a simple auth solution to work for SvelteKit + Cloudflare Pages.