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

Following React Native docs does not work and Property 'TransformStream' doesn't exist on React Native (runtime) #2367

Open
4 tasks done
lgibso34 opened this issue Nov 22, 2024 · 5 comments
Labels
bug Something isn't working needs:triage Issues that have not been investigated yet. scope:node Related to MSW running in Node

Comments

@lgibso34
Copy link

lgibso34 commented Nov 22, 2024

Prerequisites

Environment check

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

Node.js version

v18.15.0

Reproduction repository

https://github.com/lgibso34/react-native-msw

Reproduction steps

Similar to #2344 but not Jest related.

  1. checkout main branch
  2. npm start
  3. launch on device

TransformStream error

1. git checkout bug/sync
2. npm start
3. launch on device

Current behavior

Bug 1: Seems that React Native does not support the dynamic import syntax and fails to register the component in time.

Bug 2: Property 'TransformStream' doesn't exist on React Native at runtime running the synchronous code. This would also occur if the async version (bug 1) worked

Expected behavior

Bug 1: I expect the docs to explain how to get this working with additional metro config or a complete example with Metro and RN CLI. I expect the docs to accurately describe how to get msw to work in React Native.

Bug 2: I expect this to work on React Native like the docs suggest.

Async error (main)
not_registered

Sync error (bug/sync)
TransformStream no exist

@lgibso34 lgibso34 added bug Something isn't working needs:triage Issues that have not been investigated yet. scope:node Related to MSW running in Node labels Nov 22, 2024
@lgibso34 lgibso34 changed the title Following React Native does not work and Property 'TransformStream' doesn't exist on React Native (runtime) Following React Native docs does not work and Property 'TransformStream' doesn't exist on React Native (runtime) Nov 22, 2024
@kettanaito
Copy link
Member

Hi, @lgibso34. Thanks for reporting this!

We should introduce a separate export condition for react-native to exclude the Brotli decompressor from that environment. The decompression relies on the standard TransformStream web API that doesn't exist in React Native, sadly.

This is a pull request for https://github.com/mswjs/interceptors.

@kettanaito
Copy link
Member

Do you know if there's a list of all global APIs in React Native? I doubt there's DecompressionStream there either.

@lgibso34
Copy link
Author

exclude the Brotli deco

I do not, sorry. Thanks for responding though and taking a look.

@lgibso34
Copy link
Author

lgibso34 commented Nov 24, 2024

@kettanaito I'm sure I'm doing something wrong but I tried to comment out this line or well changed it do const decompressedStream = null and comment any other decompression imports in my node_modules and some how I still see ReferenceError: Property 'TransformStream' doesn't exist when I start my server

@freitagdavid
Copy link

freitagdavid commented Dec 5, 2024

Found a workaround it looks like this polyfill can get things working for the time being if you add it to your msw.polyfill.js file.

https://github.com/MattiasBuelens/web-streams-polyfill

Edit: Spoke too soon it did get me past the TransformStream issue but now I'm seeing something about MessageEvent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs:triage Issues that have not been investigated yet. scope:node Related to MSW running in Node
Projects
None yet
Development

No branches or pull requests

3 participants