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

React native support? #31

Open
evelant opened this issue Jan 29, 2022 · 2 comments
Open

React native support? #31

evelant opened this issue Jan 29, 2022 · 2 comments

Comments

@evelant
Copy link

evelant commented Jan 29, 2022

It would be nice to use Ololog in react-native. Right now it seems it primary doesn't work because the browser check is incorrect so react-native is detected as a browser and undefined properties are read.

is_browser = (typeof window !== 'undefined') && (window.window === window) && window.navigator

should be

is_browser = (typeof window !== 'undefined' && typeof document !== 'undefined') && (window.window === window) && window.navigator

in ololog and all of it's dependencies, otherwise react-native gets detected as a browser environment and crashes accessing undefined APIs.

You can also test for react-native directly with

isReactNative  = (typeof navigator != 'undefined' && navigator.product == 'ReactNative'),

It also seems that stacktracey is incompatible with react-native, primarily because of:

  1. react-native does not support synchronous XMLHttpRequests
  2. get-source assumes some node APIs exist that don't on react-native, namely process.cwd is undefined.

How feasible do you think it is to make ololog support react-native out of the box? If the browser checks are fixed it seems to be mostly working except for source mapping. When I tried to async load the source map from metro (react-native's bundler) it just hangs because the source map is enormous. I'm not really familiar with how source mapping works and editing non typescript JS written by somebody else is challenging so I'm not sure if I'm able to figure it out right now.

@GollyJer
Copy link

GollyJer commented May 3, 2023

react-native support would be awesome!

@evelant did you find any other solution?

@evelant
Copy link
Author

evelant commented May 5, 2023

@GollyJer I manually patched it with pnpm's patchedPackages feature. Since then I've given up on this since it's unmaintained and the code is really inscrutable. Instead now I emit all my logs as JSON and use https://github.com/brocode/fblog to pretty print the json in the terminal.

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

2 participants