Working on an Expo tutorial app and have restarted the project from scratch because of a random error, but somehow it has popped up again.
Following every step on the tutorial site: https://docs.expo.dev/tutorial/image-picker/
But still this error pops up. Can someone please help me understand the issue here.
The full error: Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
Check the render method of App
.
This error is located at: in RCTView (created by View) in View (created by App) in RCTView (created by View) in View (created by App) 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), js engine: hermes
**The code I've written nearly copy and paste from the site so far: **
App.js
import { StatusBar } from 'expo-status-bar';
import { StyleSheet, View, Image } from 'react-native';
import Button from './components/Button';
import ImageViewer from './components/ImageViewer';
import * as ImagePicker from 'expo-image-picker';
import { useState } from 'react';
const PlaceholderImage = require('./assets/images/background-image.png');
export default function App() {
const [selectedImage, setSelectedImage] = useState(null);
const pickImageAsync = async () => {
let result = await ImagePicker.launchImageLibraryAsync({
allowsEditing: true,
quality: 1,
});
if (!result.canceled) {
setSelectedImage(result.assets[0].uri);
} else {
alert('You did not select any image.');
}
};
return (
<View style={styles.container}>
<View style={styles.imageContainer}>
<ImageViewer
placeholderImageSource={PlaceholderImage}
selectedImage={selectedImage}
/>
</View>
<View style={styles.footerContainer}>
<Button theme="primary" label="Choose a photo" onPress={pickImageAsync} />
<Button label="Use this photo" />
</View>
<StatusBar style="auto" />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#25292e',
alignItems: 'center',
},
imageContainer: {
flex: 1,
paddingTop: 58,
},
image: {
width: 320,
height: 440,
borderRadius: 18,
},
footerContainer: {
flex: 1 / 3,
alignItems: 'center',
},
});
Button.js
import { StyleSheet, View, Pressable, Text } from 'react-native';
import FontAwesome from '@expo/vector-icons/FontAwesome';
export default function Button({ label, theme, onPress }) {
if (theme === 'primary') {
return (
<View
style={[styles.buttonContainer, {borderWidth: 4, borderColor: "#ffd33d", borderRadius: 18 }]}
>
<Pressable
style={[styles.button, { backgroundColor: "#fff" }]}
onPress={onPress}
>
<FontAwesome
name="picture-o"
size={18}
color="#25292e"
style={styles.buttonIcon}
/>
<Text style={[styles.buttonLabel, { color: "#25292e" }]}>{label}</Text>
</Pressable>
</View>
);
}
return (
<View style={StyleSheet.buttonContainer}>
<Pressable style={styles.button} onPress={() => alert('You pressed a button.')}>
<Text style={styles.buttonLabel}>{label}</Text>
</Pressable>
</View>
);
}
const styles = StyleSheet.create({
buttonContainer: {
width: 320,
height: 68,
marginHorizontal: 20,
alignItems: 'center',
padding: 3,
},
button: {
borderRadius: 10,
width: '100%',
height: '100%',
alignItems: 'center',
justifyContent: 'center',
flexDirection: 'row',
},
buttonIcon: {
paddingRight: 8,
},
buttonLabel: {
color: '#fff',
fontSize: 16,
},
});
ImageViewer.js
import { StyleSheet, Image } from 'react-native';
export default function ImageViewer({ placeholderImageSource, selectedImage }) {
const imageSource = selectedImage !== null
? { uri: selectedImage }
: placeholderImageSource;
return <Image source={imageSource} style={styles.image} />;
}
const styles = StyleSheet.create({
image: {
width: 320,
height: 440,
borderRadius: 18,
},
});```
I was trying to run the tutorial app from the Expo framework, to build a simple sticker app, and a random error appeared. When trying to recode the entire app and follow the tutorial from scratch, the error returned again.
Not sure what the issue is, but I'm sure it's something simple.
I also tried, commenting out each of the import statements at the top of the App.js file to see if it changed anything, but it didn't. No matter how many lines I commented out, the error continued to persist when running the app through the expo go app.
Any thoughts?