1

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

1
  • check my answer Commented Jul 10, 2017 at 11:22

3 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your help.
1

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

1 Comment

Hey i try to move the file , it's no working , thanks for your help any way.
1

It is because you missed single quote

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

1 Comment

Thanks for your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.