Error: Digest method not supported
I want use node:crypto module
So i followed this doc
https://developers.cloudflare.com/workers/runtime-apis/nodejs/#:~:text=Log%20in%20to%20the%20Cloudflare%20dashboard%20and%20select,compatibility%20flag%20to%20your%20Preview%20and%20Production%20deployments.
I added compatibility_flags = ['nodejs_compat'] in wrangler.toml
and code:
import crypto from 'node:crypto'
hash = crypto.createHash(method)
hash.update(date); hash.update(email)
const hdateemail = hash.digest(encoding)
console.log(hdateemail)
It works perfectly when use 'npm run dev'
but when use 'npx wrangler dev', it not works
Error: Digest method not supported
ps.
I also added flags on cli like 'npx wrangler dev --compatibility_flags nodejs_compat' and not works at all..
Node.js compatibility · Cloudflare Workers docs
Implemented Node.js runtime APIs and enablement instructions for your Worker project.
11 Replies
What is
npm run dev
doing?vite dev
You should use
wrangler dev
for testing Workers.
In this case, you're probably using an unsupported encoding.Oh okay.. i'll try change encoding
It's probably an issue with
crypto.createHash(method)
more than hash.digest(encoding)
but.. Cloudflare doc redirects to Nodejs doc and Nodejs doc can support hex... anyway i'll try different encoding
i changed encoding to 'base64' but not works. same error
Like I said, more likely to be an issue with
createHash(method)
ahhh misunderstand sorry.. bad eng
Cloudflare uses BoringSSL which means
shake128
and shake256
aren't supported iircoh thanks! it works