【问题标题】:react native Unexpected token while building app构建应用程序时反应原生意外令牌
【发布时间】:2019-07-11 11:41:48
【问题描述】:

加载依赖图,完成。 错误:捆绑失败:SyntaxError: /Users/mhd/Documents/Projects/testingscrn/node_modules/react-native/screens/HomeScreen.js: Unexpected token (19:3)

import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';
import {createStackNavigator, createAppContainer} from 'react-navigation';


class HomeScreen extends React.Component {
  static navigationOptions = {
    title: 'Welcome',
  };

  render() {
    const {navigate} = this.props.navigation;
    return (
      <Button
        title="Go to Jane's profile"
        onPress={() => navigate('Profile', {name: 'Jane'})}
      />
    );
  }

【问题讨论】:

  • 最后加上}。

标签: react-native


【解决方案1】:

您的班级缺少结尾括号。应该是这样的

.....

class HomeScreen extends React.Component {
  static navigationOptions = {
    title: 'Welcome',
  };

  render() {
    const {navigate} = this.props.navigation;
    return (
      <Button
        title="Go to Jane's profile"
        onPress={() => navigate('Profile', {name: 'Jane'})}
      />
    );
  }
}

【讨论】:

  • 我用一张图片修改了我的帖子,请检查放置括号后面临的错误。
  • @MohammadHassan 我认为您导入 HomeScreen 的路径错误。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-30
  • 2020-04-01
  • 1970-01-01
  • 2018-05-29
  • 2017-04-29
相关资源
最近更新 更多