Home > Blockchain >  React Native: Unhandled JS Exception: Can't find variable: require
React Native: Unhandled JS Exception: Can't find variable: require

Time:04-10

I'm trying to debug my react native project with expo and it recently started giving me this error. For images, I use the require statement as mentioned on the documentation to import. Now it is causing an exception to my whole project. How can I resolve this?

import { Image, StyleSheet, View } from 'react-native'

export default function Logo({ goBack }) {
  return (
    <View style={styles.logo}>
        <Image source={require('../assets/logo.jpg')} style={styles.image} onClick={goBack} />
    </View>
  )
} 

CodePudding user response:

Try stopping the server, quitting your virtual device, and start over.

It seems to be a compilation issue, as indeed, require should work.

CodePudding user response:

import { Image, StyleSheet, View } from 'react-native'
import image from '../assets/logo.jpg'
export default function Logo({ goBack }) {
  return (
    <View style={styles.logo}>
        <Image source={image} style={styles.image} onClick={goBack} />
    </View>
  )
} 

try this code

  • Related