worried-planet-2191
03/05/2024, 8:54 PMhappy-autumn-40938
03/06/2024, 5:40 AMsetPolyfills({
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.microscopic-table-65564
03/06/2024, 4:21 PMmicroscopic-table-65564
03/06/2024, 5:04 PMSubtleCrypto 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:
//_app.js
import { Crypto } from '@peculiar/webcrypto';
const crypto = new Crypto();
setPolyfills({
SubtleCrypto: crypto.subtle,
});