9

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
Alex Parij
  • 1,168
  • 1
  • 14
  • 21
  • Does this answer your question? [Generating UUID in react using crypto api](https://stackoverflow.com/questions/71127816/generating-uuid-in-react-using-crypto-api) – Son Nguyen Jan 11 '23 at 15:10

3 Answers3

8

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

here are example for crypto

S.Chen
  • 120
  • 4
8

For me, it worked when I used import * as

import * as crypto from 'crypto';
Vikash Rathee
  • 1,776
  • 2
  • 25
  • 43
1

You can use it with

const crypto = require('crypto');

or also by using

import crypto from "crypto"

gilzonme
  • 150
  • 1
  • 7