Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: crypto.randomUUID is not a function #12

Open
cvthang56th2 opened this issue Dec 10, 2024 · 7 comments
Open

TypeError: crypto.randomUUID is not a function #12

cvthang56th2 opened this issue Dec 10, 2024 · 7 comments

Comments

@cvthang56th2
Copy link

cvthang56th2 commented Dec 10, 2024

I'm using my ip to test in my mobile, but I got this error
image

I'm using Next.js 14, my root layout

import Provider from './provider'

const RootLayout = ({
  children,
  params: { locale },
}: {
  children: React.ReactNode
  params: { locale: string }
}) => {
  return (
    <html lang={locale}>
      <body>
        <NavigationGuardProvider>
          <Provider>{children}</Provider>
        </NavigationGuardProvider>
      </body>
    </html>
  )
}

export default RootLayout```



Please help me fix it!!!
@ypresto
Copy link
Collaborator

ypresto commented Dec 11, 2024

Can you provide name and version of your browser? It might be rare one 🤔

image

@cvthang56th2
Copy link
Author

cvthang56th2 commented Dec 11, 2024

Yes, I'm using Chrome Version 131.0.6778.109
image

Both of my Safari and Chrome have this issue, but in live (https), it's still work well

@patik
Copy link

patik commented Dec 16, 2024

I'm getting the same error while running Jest

@peinguin
Copy link
Contributor

The way to fix this is to use a secure connection.

@cvthang56th2
Copy link
Author

My temp solution:

  • Go to:
    node_modules/next-navigation-guard/dist/utils/historyAugmentation.js and node_modules/next-navigation-guard/dist/utils/setupHistoryAugmentationOnce.js
  • Edit these lines:
    function newToken() { return crypto.randomUUID().substring(0, 8); }
    into:
    function newToken() { return Math.random().toString(36).substring(2, 10); }

@peinguin
Copy link
Contributor

peinguin commented Jan 6, 2025

I got it on prod also. In iPhone 13 pro max.

@jamespantalones
Copy link

yeah, this will not work in non-secure browser contexts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants