DEV Community

Erick Calder
Erick Calder

Posted on

NextJs UUID

I'm trying this

import { randomUUID } from 'crypto'
var id = randomUUID()

in my NextJs app but I'm getting this error:

index.js?46cb:369 Uncaught TypeError: (0 , crypto_WEBPACK_IMPORTED_MODULE_5.randomUUID) is not a function
at eval (index.js?bee7:8:20)
at Module../pages/index.js (index.js?ts=1649816623582:5680:1)
at Module.options.factory (webpack.js?ts=1649816623582:618:31)
at __webpack_require
_ (webpack.js?ts=1649816623582:37:33)
at fn (webpack.js?ts=1649816623582:287:21)
at eval (?595a:5:16)
at eval (route-loader.js?ea34:235:51)

it seems like the crypto library is available to middleware in NextJs (though it should be available at the browser) but that seems complicated to implement. can anyone suggest how to generate a UUID in NextJs?

Top comments (0)