在react-native

时间:2017-04-15 21:14:29

标签: javascript node.js react-native

我正在尝试使用react-native和react-native-weback-server。

当我运行rnws start时,我在node_modules/react-native/local-cli/server/util/launchChrome.js:15

处得到一个SyntaxError
function getChromeAppName(): string {
                           ^
SyntaxError: Unexpected token :

查看该文件,我看到了方法:

function getChromeAppName(): string {
  switch (process.platform) {
  case 'darwin':
    return 'google chrome';
  case 'win32':
    return 'chrome';
  default:
    return 'google-chrome';
  }
}

然而,这不适用于我的Node版本(7.9.0)。我不知道这是什么版本的Javascript这是有效的语法,如果我使用正确的babel转换器。

这是我的NPM依赖项:

  "dependencies": {
    "babel-core": "^6.24.1",
    "babel-loader": "^6.4.1",
    "babel-plugin-transform-react-jsx": "^6.24.1",
    "babel-preset-es2016": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "coffee-loader": "^0.7.3",
    "coffee-script": "^1.12.5",
    "react": "^15.5.4",
    "react-dom": "^15.5.4",
    "react-native": "^0.43.3",
    "react-native-webpack-server": "^0.9.3",
    "webpack": "^2.4.1",
    "webpack-dev-server": "^2.4.2"
  }

和webpack.config.js

var path = require('path');
var webpack = require('webpack');
module.exports = {
  entry: './app.coffee',
  output: { filename: 'bundle.js' },
  module: {
    loaders: [
      {
        test: /.jsx?$/,
        loader: 'babel-loader',
        exclude: /node_modules/,
        query: {
          presets: ['es2016', 'react']
        }
      },
      {
        test: /\.coffee$/,
        loader: "coffee-loader" 
      }
    ]
  },
};

1 个答案:

答案 0 :(得分:0)

它是Flow

流式语法文件的头部通常会有@flow条评论,您可以看到this file does

a Babel plugin来解析此语法。