'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


Solution 1:[1]

before use crypto module, just import import crypto from "crypto"

here are example for crypto

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 S.Chen