This message was deleted.
# ask-questions
w
This message was deleted.
h
You may still need to apply the polyfill via
Copy code
setPolyfills({
  SubtleCrypto: require("node:crypto").webcrypto.subtle,
});
Depending on Node runtime, this may or may not be needed. Node 18+ should have
crypto.subtle
available on
globalThis
, Node 17 only has
crypto
(no .subtle), and Node 16 has nothing.
m
Thanks @happy-autumn-40938. I’ll give it a try. I am using node 18+, though
Here’s an update on this if it’s useful for anyone. The
SubtleCrypto
polyfill will not work on NextJS for client-side code, as
node:crypto
is unavailable in the browser environment; this will only work on server-side code or API routes. I ended up using this approach:
Copy code
//_app.js
import { Crypto } from '@peculiar/webcrypto';

const crypto = new Crypto();
setPolyfills({
  SubtleCrypto: crypto.subtle,
});
150 Views