Expo Production Mode
LucasOliveiraS opened this issue ยท 5 comments
Hello! ๐
Issue Description
I have a React Native application with Expo and I'm trying to throw an error that is triggered by a button.
onPress={() => { throw new Error('This is a test error!'); }}
I'm running the application in Production Mode using expo start --ios --no-dev --minify
to see the error screen and try to simulate a real case, but I'm not able to see it. In development mode, I have no problems following the example demo on Expo: https://snack.expo.io/@carloscuesta/react-native-error-boundary.
Would anyone happen to know how I could go about fixing this issue?
Thanks for the help and time!
Hey! ๐๐ผ
I've been not using Expo for a while, but I found this on the docs:
Not sure if this will be of any help but my guess is that Expo is handling the error in Production
mode reloading the application and you're not able to see the error screen ๐
Could be related with #37
Thanks for the clarification! I build an APK of my Expo application to try it in a real scenario, but I guess react-native-error-boundary
is not catching the error.
My app:
import React from 'react';
import { StatusBar } from 'expo-status-bar';
import { Text, View, Button } from 'react-native';
import ErrorBoundary from 'react-native-error-boundary';
const ComponentWithError = () => {
function handleTest() {
throw new Error('This is a test error thrown by handleTest.');
}
return (
<View style={styles.container}>
<Button title='Throw error' onPress={handleTest} />
</View>
)
}
export default function App() {
return (
<ErrorBoundary>
<View>
<Text>Open up App.js to start working on your app!</Text>
<StatusBar style="auto" />
<ComponentWithError />
</View>
</ErrorBoundary>
);
}
On my mobile device, when I press the button, the app close, I guess because it's not catching the error that I threw.
Have you faced something like that?
Hey @LucasOliveiraS can you try running the same code from the Expo example in production mode to check if you can see the error screen?
I think the problem is that you're throwing inside of an event handler and as stated in the React docs, error boundaries don't catch this
https://reactjs.org/docs/error-boundaries.html#how-about-event-handlers
@carloscuesta, I ran the Expo example in production mode and I could see the error screen. Yeah, my bad, I'm throwing the error inside an event handler, that's why react-native-error-boundary
is not catching. Thanks so much for the explanation! I will try to simulate an error in the UI.
No worries! That's why I added the example in the first place but missed this detail in your original comment ๐