Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Web Crypto API in NextJS, but getting error 'crypto is not defined'

Can I use web crypto api in NextJS?

I tried to use

crypto.subtle.digest('SHA-256', data)

but getting an error

ReferenceError: crypto is not defined
like image 997
Alex Parij Avatar asked Nov 27 '25 12:11

Alex Parij


2 Answers

Before using the crypto module, just import it with import crypto from "crypto"

Here are examples for crypto

like image 177
S.Chen Avatar answered Nov 29 '25 02:11

S.Chen


For me, it worked when I used import * as

import * as crypto from 'crypto';
like image 38
Vikash Rathee Avatar answered Nov 29 '25 01:11

Vikash Rathee



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!