React-native-web: ErrorUtils is undefined in React Native for Web

Created on 18 May 2020  路  5Comments  路  Source: necolas/react-native-web

The problem

ErrorUtils is undefined and therefore unusable for globally capturing uncaught JS exceptions.

I am not sure how else to proceed, but any advice on how to approach this would be wonderful, I have scoured the internet for answers before coming here looking for guidance.

How to reproduce

Simplified test case:

image

Steps to reproduce:

  1. Reference the global ErrorUtils object from React Native in any RN4W project
  2. See that it's always undefined

Expected behavior

Environment (include versions). Did this work in previous versions?

  • React Native for Web (version): 0.12.2
  • React (version): 16.11.0
  • Browser: Chrome 80.0.3987.163 (Official Build) (64-bit)

Most helpful comment

I don't know. Maybe @EvanBacon has done something for this in Expo. I don't know why RN added this as a global but Expo is the library that polyfills all the weird RN environment stuff, while RNW is focused on the APIs exported from react-native

All 5 comments

There is no ErrorUtils global in the browser so you should check it exists before calling it

@necolas thank you for your response - I was hoping you had a preferred way / suggestion for handling all uncaught JS exceptions with React Native for Web? I assume window.onError() or using some SDK wrapping this would be the best option.

I don't know. Maybe @EvanBacon has done something for this in Expo. I don't know why RN added this as a global but Expo is the library that polyfills all the weird RN environment stuff, while RNW is focused on the APIs exported from react-native

@daxfrost Did you ever get around this?

@altany I haven't spent time on this in a little while, but the reality is that the ErrorUtils is bound to the React Native embedded usage of JavaScriptCore engine - not the browser's Javascript engine, so technically you should simply avoid using ErrorUtils altogether in RN4W, by abstracting away from it and using standard window.onError methods, which is utilized by many web SDKs (e.g: https://github.com/rollbar/rollbar.js/blob/0ffa71592d4b6a312f832134121d745c672811f0/src/browser/globalSetup.js#L1-L25)

Was this page helpful?
0 / 5 - 0 ratings