question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React Native support is broken

See original GitHub issue

This code was taken directly from the React Native GraphQL branch in the examples repository (https://github.com/mswjs/examples/tree/examples/gql-react-native/examples/graphql-react-native-apollo). I’ve been unable to get that to work at all for other reasons, so I thought I’d create a new repository using the latest versions of everything to demonstrate the error I’m receiving.

https://github.com/wwdrew/mswjs-react-native-failing

Environment

Name Version
msw 0.27.0
browser n/a
react-native 0.63.4
OS MacOS 11.2.1

Current behavior

Metro crashes with this stack trace:

error: Error: Unable to resolve module os from <obscured>/AnotherTest/node_modules/msw/native/lib/index.js: os could not be found within the project.

If you are sure the module exists, try these steps:
 1. Clear watchman watches: watchman watch-del-all
 2. Delete node_modules and run yarn install
 3. Reset Metro's cache: yarn start --reset-cache
 4. Remove the cache: rm -rf /tmp/metro-*
  4 |
  5 | var XMLHttpRequest = require('node-request-interceptor/lib/interceptors/XMLHttpRequest');
> 6 | var os = require('os');
    |                   ^
  7 | var tty = require('tty');
  8 | var events_1 = require('events');
  9 | var nodeRequestInterceptor = require('node-request-interceptor');

Expected behavior

Expecting the API call to be successful and not crash the bundler.

Screenshots

msw-error

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:7
  • Comments:15 (12 by maintainers)

github_iconTop GitHub Comments

7reactions
wwdrewcommented, Mar 10, 2021

I’ve had a bit more time this evening to work on this and have managed to get it working a little further, but with some big caveats.

First of all, in order to import ‘events’ I’ve had to install the ‘events’ package, otherwise it fails trying to load that package. This is only used in StrictEventEmitter, I haven’t tracked down where this is imported so I’m not sure yet how to overcome this one. Since it’s referring to EventEmitter, I’m hoping I can change the import to bring in the RN version rather than going through the events package. If someone out there has any suggestions on this I’d be really happy to hear them.

The next problem is the usage of ‘url’ in the getPublicUrlFromRequest function. Just as a hack I’ve removed the function call to ‘format’ entirely and there are no more runtime errors - result, again! However, the call now fails with a ‘Network request failed’. According to the TS annotations the format function is deprecated anyway and should probably be updated, but that still won’t solve the missing ‘url’ package. Again, not sure how to overcome this one.

I do have some good news though, I’ve added ‘chalk’ to the list of external modules in the rollup config and it’s cleared up the ‘tty’ and ‘os’ imports.

Hopefully someone else out there has some ideas on how to fix these issues?

4reactions
jorgemastacommented, Jul 12, 2021

Really nice work @wwdrew !!

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Native support is broken · Issue #39 - GitHub
React native 0.10.0 fixes this problem: process.env.NODE_ENV: This value is defined to be "production" or "development" based on your current ...
Read more >
Troubleshooting - React Native
These are some common issues you may run into while setting up React Native. If you encounter something that is not listed here,...
Read more >
React Native vs Felgo (Best Alternative to Create Mobile Apps)
With React Native, support for tooling is limited. Commands are run from a terminal and it does not ship with a dedicated IDE...
Read more >
React Native Web app made a few months ago suddenly has ...
System theme is broken--only shows the light theme. Whole groups of components, specifically mapped components, vanished from Web and iOS, and ...
Read more >
React navigation in react-native v0.60 is broken - Stack Overflow
Yep react-native-gesture-handler needs to migrate to androidX. Try : npm install --save-dev jetifier npx jetify.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found