Cloudflare with node compatibility

I am trying to deploy remix app which is built with vite on cloudflare. I am getting errors like ERROR: Could not resolve "crypto". I added compatibility_flags = [ "nodejs_compat" ] flag into the wrangler file. I do not directly use crypto module, the library I use uses it. Does anyone know how to make it work so that those libraries import with node: prefix?
1 Reply
Chaika
Chaika4mo ago
If you're using Cloudflare Pages you have more limited options. They're working on a compat flag experimental:nodejs_compat_v2 to make the node: prefix not required but it's still experimental/being worked on. You could try monkeypatching it if your code runs before the lib does, assigning what you need to globalThis.crypto from the node: prefix but not everything is supported eitherway: https://developers.cloudflare.com/workers/runtime-apis/nodejs/crypto/ Patching the lib is the last option
Cloudflare Docs
Crypto | Cloudflare Workers docs
The node:crypto module provides cryptographic functionality that includes a set of wrappers for OpenSSL’s hash, HMAC, cipher, decipher, sign, and verify functions.
Want results from more Discord servers?
Add your server