【问题标题】:react-native : Parsing error: Unexpected token <react-native:解析错误:意外的令牌<
【发布时间】:2016-12-07 09:33:23
【问题描述】:

我是 react-native 的新手,我在 Windows 7 上使用 Atom GUI 1.12.6 并在 Android 手机中使用 Exponent 部署应用程序 这是我的代码

'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 编辑器中,它显示“解析错误:意外令牌

【问题讨论】:

    标签: react-native


    【解决方案1】:

    你的渲染方法有错别字..

    render(){}
    

    改为:

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

    【讨论】:

    • 谢谢,现在我可以在手机中部署应用程序,但是在 Atom 编辑器中的文本控件中显示“解析错误:意外令牌
    • 我对 Atom 不熟悉,但你可能使用了错误的 Atom 语法高亮,无法识别 react..或者 eslint 没有配置好..见react Atom pluginconfigure eslint for react in Atom
    猜你喜欢
    • 1970-01-01
    • 2020-07-05
    • 2021-03-28
    • 2018-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-02
    • 2019-02-19
    相关资源
    最近更新 更多