Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: crypto.randomUUID is not a function

My Next.js app works like a charm on http://localhost:3000/.

I added the following line to my hosts file.

127.0.0.1 whatever.local

When I connect to http://whatever.local:3000/, my client-side components return the following error.

TypeError: crypto.randomUUID is not a function

I use crypto.randomUUID() when creating child objects such as in the the following example.

{lookupItemList.map((lookupItem: LookupItem) =>
    <option
        key={crypto.randomUUID()}
        value={lookupItem.key}>
        {lookupItem.value}
    </option>
)}
like image 203
Fabio Scagliola Avatar asked May 07 '26 05:05

Fabio Scagliola


1 Answers

first, it's not a good practice to use crypto.randomUUID() as key of your elements, instead use item id's or any other specific data on your items.

and for your question,Note that window.crypto.randomUUID is only available under HTTPS context. localhost is treated a secure origin, even without HTTPS. For everything apart from localhost, you do need HTTPS.

like image 58
Maziar parsi Avatar answered May 09 '26 18:05

Maziar parsi



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!