Morton
Morton

Reputation: 5760

Unexpected token when adding Image

I can see my Text: I am HomeScreen as well when i compile the project. My problem is when adding a Image , it shows the error HomeScreen.js: Unexpected token .

I can't see my code has any problem . Is any one can tell me what step i miss it ? That would be appreciated.

Here is my HomeScreen.js:

import React, { Component } from 'react';
import { View, Text, Image } from 'react-native';

class HomeScreen extends Component {
  static navigationOptions = {
    title: 'Home'
  };
  // When i add Image , i will get a error.
  render(){
    return (
      <View>
        <Image
          source={require(../img/home.png)}
          fadeDuration={0}
          style={{width: 20, height: 20}}
         />
        <Text>I am HomeScreen</Text>
      </View>
    );
  }
};

export default HomeScreen;

Here is my root: enter image description here

Upvotes: 1

Views: 1486

Answers (3)

Priyesh Mishra
Priyesh Mishra

Reputation: 119

source={require(../img/home.png) should be source={require('../img/home.png') however whenever u add images u need to restart web server .just restart by react-native start

Upvotes: 2

Jigar Shah
Jigar Shah

Reputation: 6223

It is because you missed single quote

source={require('../img/home.png')}

Upvotes: 1

karri jayanth
karri jayanth

Reputation: 32

For your webpack to run I think all of your js files should be in components folder try replacing your HomeScreen.js file into components folder and run it again .Hope it works

Upvotes: 1

Related Questions