Skip to content

TypeError: crypto.randomUUID is not a function with msw 2.2.12 #2111

@maxime-bc

Description

@maxime-bc

Prerequisites

Environment check

  • I'm using the latest msw version
  • I'm using Node.js version 18 or higher

Browsers

Chromium (Chrome, Brave, etc.), Firefox, Safari

Reproduction repository

https://github.com/maxime-bc/test-msw

Reproduction steps

npm install && npx vite --host 0.0.0.0

Then, try to access the website using both local and network addresses. In the tab accessed by the network address, the error will appear in the console.

Then, downgrade msw to 2.2.11 and start the dev server again:
npm install msw@2.2.11 && npx vite --host 0.0.0.0

Again, access the website using both local and network addresses. This time the error will not appear.

Current behavior

Hello,

I'm encountering the following behavior: when accessing a website via its local address, msw works. But when using a network address, the following error is raised in the browser console : TypeError: crypto.randomUUID is not a function.

As far as I understand, this is the intended behavior as crypto.randomUUID is only available in secure contexts, such as localhost.

What I found strange is that prior updating to msw 2.2.12, I was on version 2.1.4 and I never had any issues with crypto.randomUUID, which was introduced in 2.0.0.

I tried version 2.2.11 and had no issues, the error is not raised at all so it seems to be a problem with version 2.2.12 ?

Expected behavior

This error should not be raised ?

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingscope:browserRelated to MSW running in a browser

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions