我正在尝试使用react-native和react-native-weback-server。
当我运行rnws start
时,我在node_modules/react-native/local-cli/server/util/launchChrome.js:15
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"
}
]
},
};