Trouble deploying Auth.js with Sveltekit on Cloudflare Pages - `node:crypto`
Hi all! I've been having a fun time trying to debug a build issue for the past few days using Auth.js on a Cloudflare Pages project built using SvelteKit.
The problem seems to stem from the use of node built-in modules, but even after enabling
nodejs_compat
, I'm facing errors related to the use of node:crypto
.
Could anyone shine some light on where to go about debugging this issue?
(When deployed to pages directly, the error is the same, minus the stack trace.)
3258fd10.dms-hgm.pages.dev
Acc. ID: 84e974647453d280b13cd8438d22d3c34 Replies
Currently, the
vite.config.ts
is fairly stock:
I've tried using resolve:{alias:{}} to try and polyfill it, but I'm not massively familiar with Vite, and that may be more of a sveltekit issue anyway.
The wrangler.toml currently looks like this:
I've been trying to do the exact same thing but
node:crypto
seems to not implement constants
unfortunately. https://developers.cloudflare.com/workers/runtime-apis/nodejs/crypto/Cloudflare Docs
Crypto · Cloudflare Workers docs
To use Node.js APIs in your Worker, add the nodejs_compat compatibility flag to your wrangler.toml file.
Eventually I tracked down this issue from
jose
, which is a library used by auth.js, but it seems to just suggest disabling node compat... which breaks other things 😬I was able to solve this by explicitly installing
@auth/core
. For any future searchers, related issue is https://github.com/nextauthjs/next-auth/issues/11184GitHub
Getting "The requested module 'node:crypto' does not provide an exp...
Environment System: OS: Linux 6.9 Arch Linux CPU: (32) x64 AMD Ryzen 9 3950X 16-Core Processor Memory: 113.16 GB / 125.74 GB Container: Yes Shell: 5.9 - /usr/bin/zsh Binaries: Node: 22.3.0 - /usr/b...