crypto.getRandomValues() is not a function

Hi, I have a NodeJS server that has a function like this:

 uuidv4: function() {
        return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c =>
          (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)

It works fine on localhost. However, when I deploy my server to render and then try to access the api route that uses this function I get the following error:

(node:64) UnhandledPromiseRejectionWarning: TypeError: crypto.getRandomValues is not a function

Why is this? My ‘crypto’ object is defined at the top of the file along with everything else and there are no issues with other functions, and this particular one works fine locally. How can I fix this issue? Thanks.


Crypto was added in Node 15, and the Render default is Node 14.

Maybe check you’re specifying your Node version to match the one you developed on.


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.