Could not resolve "crypto" on wrangler pages publi...
# pages-help
d
Every time I try
Copy code
wrangler pages publish
I get the error in the screenshot. The Build has been working fine with in dev using the node-compat flag.
Copy code
npx wrangler pages dev build  --node-compat
I also followed the errors directions and added
Copy code
node_compat = true
to my wrangler.toml file. I also have
Copy code
node_compat
set up in production & preview compatibility flags. I would love help getting past this error and get back publishing. thank you 🙂 My Pages.dev: nftdev-igorandandre.pages.dev My account ID: 596032e44d9793dca36eb2e347ab8ead
s
I believe you'll need to import
node:crypto
rather than just crypto
And you'll also want
--compatibility-flags nodejs_compat
instead of
--node-compat
for your dev command
A confusing difference between
node-compat
and
nodejs_compat
, is that
node-compat
is a bunch of old polyfills provided by esbuild, which inflate your bundle size and can be unreliable, whereas
nodejs_compat
is the new flag that provides built in APIs withh no cost to the size of your worker
w
node compat doesn't support crypto yet
s
Oh also that's true 😅
but it's a wip at the moment
d
Awesome thank you for the quick response. I will try right now.
s
Note that, as walshy said, crypto won't work regardless at the moment, but some other modules such as
buffer
,
util
, etc
d
Oh ok. Hm.. Its strange it was working in 'npx wrangler pages dev'. I'm using the square sdk and it uses the crypto. Am I out of luck getting it working with pages functions?
s
I'm not familiar with that library, but it may be possible that you can use it, or an alternative, with the web crypto API available in workers
Or you can wait until the node crypto support is finished, in which case it should work without any changes
d
Ok perfect. thank you I really appreciate it. Do you have any timeline on when the crypto support will be finished?
s
Looks like the initial pull was merged earlier today , so hopefully not far away
There'll still need to be a new workerd release both publically, and internally before it's usable though
Ah, it looks like that doesn't implement the full library either
d
ok thank you for the help. 🙂
Hi Walshy, I was wondering if there is any update on the inclusion of the crypto library? If not what would be the best way to track the progress.
k
https://github.com/cloudflare/workerd/pull/457 was merged two weeks ago so I expect it to be in the next runtime release
d
wow amazing thank you for the update! Do you know when that release it. I'm closing in on the end of my project and trying to figure if i should hold off on my release and wait for this.
p
Is there an update anywhere as to whether this is accessible yet?
s
There's still a number of pulls open around it