How to fix Uncaught TypeError: window.crypto.randomUUID is not a function in react JS app using MSAL after deploying it in IIS

bharani kumar 30 Reputation points
2023-10-10T10:46:33.68+00:00

After deploying the React js application which uses Single sign on process using MSAL library, the following error occurs in IIS.

Uncaught TypeError: window.crypto.randomUUID is not a function
    at d.value (CryptoOps.ts:70:5)
    at e.value (EventHandler.ts:64:5)
    at A.value (StandardController.ts:1801:5)
    at o.value (PublicClientApplication.ts:167:5)
    at MsalProvider.tsx:88:37
    at ol (react-dom.production.min.js:244:332)
    at Cc (react-dom.production.min.js:286:111)
    at react-dom.production.min.js:282:391
    at _ (scheduler.production.min.js:13:203)
    at MessagePort.R (scheduler.production.min.js:14:128)
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
22,888 questions
{count} votes

4 answers

Sort by: Most helpful
  1. Tony Nguyen 5 Reputation points
    2023-10-17T03:08:23.01+00:00

    Hi, I have the same issue, but a workaround for this is installing @azure/msal-react 2.0.2 and the build will work like normal. Cheers.

    1 person found this answer helpful.
    0 comments No comments

  2. Raman Zhukouski 0 Reputation points
    2023-10-10T16:21:49.12+00:00

    I have the same issue, but only on Android using client app


  3. Bruce (SqlWork.com) 69,276 Reputation points
    2023-12-19T21:23:55.24+00:00

    this is a missing browser method. you must be using an old browser, just add a polyfill:

    https://www.npmjs.com/package/crypto-randomuuid

    0 comments No comments

  4. Ben Gunnewijk 0 Reputation points
    2023-12-20T12:42:44.65+00:00

    Okay I know what caused the error for me.
    window.crypto.randomUUID is only available under HTTPS context: https://developer.mozilla.org/en-US/docs/Web/API/Crypto/randomUUID

    My website was being deployed to a linux server without domain name or certificate. And thus on localhost the crypto functions were loaded but on the http website they never get loaded, not even with the crypto-randomuuid polyfill.

    Found this in a similar issue on the parcel bundler:
    https://github.com/parcel-bundler/parcel/issues/8820

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.