react-native:解析错误:意外的令牌<

时间:2016-12-07 09:33:24

标签: react-native

我是反应原生的新手,我在Windows 7和Exponent上使用Atom GUI 1.12.6在Android手机中部署应用程序 这是我的代码

'use strict';

import Exponent from 'exponent';
import React, {Component} from 'react';

import { AppRegistry, Text } from 'react-native';

class App extends Component{
    constructor(props, context) {
        super(props, context);
        this.state = {
        };
    }

    render(){}
      return (
          <Text>Hello world again!</Text>
      );
   }
}
Exponent.registerRootComponent(App);

.eslintrc文件包含规则:

{
    "extends": "airbnb/base",
    "plugins": [
        "react"
    ],
    "env": {
        "node": true,
        "jasmine": true,
    },
    "rules": {
        "indent": [1, 4],
        "no-console": 0,
        "no-unused-vars": [1, {"vars": "local", "args": "none"}],
        "react/forbid-prop-types": 1,
        "react/jsx-boolean-value": 1,
        "react/jsx-closing-bracket-location": 1,
        "react/jsx-curly-spacing": 1,
        "react/jsx-indent-props": 1,
        "react/jsx-key": 1,
        "react/jsx-max-props-per-line": 1,
        "react/jsx-no-duplicate-props": 1,
        "react/jsx-no-undef": 1,
        "react/jsx-quotes": 1,
        "react/jsx-sort-prop-types": 1,
        "react/jsx-sort-props": 1,
        "react/jsx-uses-react": 1,
        "react/jsx-uses-vars": 1,
        "react/no-danger": 1,
        "react/no-did-mount-set-state": 1,
        "react/no-did-update-set-state": 1,
        "react/no-direct-mutation-state": 1,
        "react/no-multi-comp": 1,
        "react/no-set-state": 1,
        "react/no-unknown-property": 1,
        "react/prefer-es6-class": 1,
        "react/prop-types": 1,
        "react/react-in-jsx-scope": 1,
        "react/require-extension": 1,
        "react/self-closing-comp": 1,
        "react/sort-comp": 1,
        "react/wrap-multilines": 1,
        "id-length": 0,
    },
    "ecmaFeatures": {
      "jsx": true
    },
}

获取错误:  在文本控件的Atom编辑器中显示&#34;解析错误:意外的令牌&lt;&#34;如果你忽略它并使用手机中的指数开始在Android手机中部署,它会显示红色屏幕并显示错误:&#34;意外的令牌&#39;&lt;&#39;&#34;&#34;&#34;

1 个答案:

答案 0 :(得分:3)

你在渲染方法中有一个拼写错误..

render(){}

更改为:

render() {
    return (
        <Text>Hello world again!</Text>
    );
}