【问题标题】:React Native ExportiingReact Native 导出
【发布时间】:2017-09-01 16:01:35
【问题描述】:

我在尝试构建我的 React Native 包时收到以下错误。

语法错误 components/Example/index.js: Unexpected token, expected ; (1:20)

我不确定我的 eslint/babel 配置是否有问题。这是文件。

组件/示例/index.js

export default from './View'

组件/示例/View.js

import React, { Component, PropTypes, Button } from 'react';
import { connect } from 'react-redux'
import { updateExampleData } from '../../actions/example'

class Example extends Component {
  static propTypes = {
    title: PropTypes.string.isRequired,
    navigator: PropTypes.object.isRequired,
    exampleProp: PropTypes.object.isRequired
  }

  const incrementData = () => {
    const newIncrement = this.props.exampleProp + 1
    updateExampleData(newIncrement)
  }

  render() {
    return (
      <View>
        <Text>exampleData: {this.props.exampleProp} </Text>
          <Button
            onPress={incrementData}
            title="Increment Data"
            color="#841584"
          />
      </View>
    )
  }
}

  const mapStateToProps = (state, props) => {
    const exampleProp = state.example.example
    const newProps = {
      exampleProp: exampleProp
    }
    return newProps
  }

export default connect(mapStateToProps)(Example)

package.json

{
  "name": "SportsApp",
  "version": "0.1.0",
  "private": true,
  "devDependencies": {
    "babel-eslint": "^7.2.3",
    "babel-preset-react-native": "^3.0.2",
    "eslint": "^4.5.0",
    "eslint-config-standard": "^10.2.1",
    "eslint-plugin-import": "^2.7.0",
    "eslint-plugin-node": "^5.1.1",
    "eslint-plugin-promise": "^3.5.0",
    "eslint-plugin-react": "^7.3.0",
    "eslint-plugin-standard": "^3.0.1",
    "jest-expo": "~19.0.0",
    "react-native-orientation": "^3.0.0",
    "react-native-orientation-listener": "0.0.4",
    "react-native-scripts": "1.1.0",
    "react-native-tableview-simple": "^0.16.8",
    "react-redux": "^5.0.5",
    "react-test-renderer": "16.0.0-alpha.12",
    "redux": "^3.7.2",
    "redux-logger": "^3.0.6",
    "redux-promise": "^0.5.3",
    "redux-thunk": "^2.2.0"
  },
  "main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
  "scripts": {
    "start": "react-native-scripts start",
    "eject": "react-native-scripts eject",
    "android": "react-native-scripts android",
    "ios": "react-native-scripts ios",
    "test": "node node_modules/jest/bin/jest.js --watch"
  },
  "jest": {
    "preset": "jest-expo"
  },
  "dependencies": {
    "expo": "^19.0.0",
    "react": "16.0.0-alpha.12",
    "react-native": "^0.46.1"
  }
}

eslint.json

{
    "parser": "babel-eslint",
    "env": {
        "browser": true
    },
    "plugins": [
        "react"
    ],
    "extends": [
        "eslint:recommended",
        "plugin:react/recommended"
    ],
    "rules": {
    }
}

.babelrc

{
  "presets": ["react-native"]
}

我之前写过 react-redux,但我没有为那个项目做解析配置,所以我想知道语法错误是否与此有关。我很确定我的组件的 index.js 文件的语法与语法错误所在的提供的文件中的语法相同。

【问题讨论】:

    标签: javascript json react-native


    【解决方案1】:

    您可以尝试以下方法吗?

    export { default } from './View'
    

    在你的 index.js 中

    【讨论】:

    猜你喜欢
    • 2018-07-18
    • 1970-01-01
    • 1970-01-01
    • 2018-07-21
    • 1970-01-01
    • 1970-01-01
    • 2017-05-02
    • 2017-04-12
    • 2019-05-08
    相关资源
    最近更新 更多