I tried searching SO for answer but could not seem to find it. I wrote simple app to test functionality of opening camera. However I keep getting error.
Code is as follows:
import { View, Button, StyleSheet } from 'react-native';
import { Camera } from 'expo-camera';
const App = () => {
const [hasPermission, setHasPermission] = useState(null);
const [cameraOpen, setCameraOpen] = useState(false);
const requestCameraPermission = async () => {
const { status } = await Camera.requestCameraPermissionsAsync();
setHasPermission(status === 'granted');
};
const openCamera = async () => {
if (hasPermission === null) {
await requestCameraPermission();
}
if (hasPermission) {
setCameraOpen(true);
} else {
alert('Camera permission is required to use this feature.');
}
};
if (cameraOpen) {
return (
<Camera style={styles.camera}>
<Button title="Close Camera" onPress={() => setCameraOpen(false)} />
</Camera>
);
}
return (
<View style={styles.container}>
<Button title="Open Camera" onPress={openCamera} />
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
camera: {
flex: 1,
justifyContent: 'flex-end',
alignItems: 'center',
},
});
export default App;
However every single time I get this error:
Check your code at App.js:28.
in App (created by withDevTools(App))
in withDevTools(App)
in RCTView (created by View)
in View (created by AppContainer)
in RCTView (created by View)
in View (created by AppContainer)
in AppContainer
in main(RootComponent)
(NOBRIDGE) ERROR Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object.
Check your code at App.js:28.
in App (created by withDevTools(App))
in withDevTools(App)
in RCTView (created by View)
in View (created by AppContainer)
in RCTView (created by View)
in View (created by AppContainer)
in AppContainer
in main(RootComponent)
(NOBRIDGE) ERROR Warning: Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
Check the render method of `App`.
This error is located at:
in App (created by withDevTools(App))
in withDevTools(App)
in RCTView (created by View)
in View (created by AppContainer)
in RCTView (created by View)
in View (created by AppContainer)
in AppContainer
in main(RootComponent)
(NOBRIDGE) ERROR Warning: Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
Check the render method of `App`.
This error is located at:
in App (created by withDevTools(App))
in withDevTools(App)
in RCTView (created by View)
in View (created by AppContainer)
in RCTView (created by View)
in View (created by AppContainer)
in AppContainer
in main(RootComponent)
I run Expo server by using npx expo start and have all dependencies properly installed. For testing purposes I am using some Honor phone that has camera and all working normally but app crashes every time I try to open camera up. Help?