我端起GiftedMessager意外令牌模塊構建失敗:SyntaxError錯誤
1:https://github.com/FaridSafi/react-native-gifted-messenger上網絡。 我能解決的問題previous
現在我被困在新的問題,我不能夠端口反應本地解析的文字。錯誤我的終端窗口上發現的是
[684] ./~/react-native-communications/AKCommunications.js 5.16 kB {0} [built]
ERROR in ./~/react-native-parsed-text/src/ParsedText.js
Module build failed: SyntaxError: /Users/Gaurav/WebWork/ReactWeb/Practise/react-native-web-exploding-hearts-master/node_modules/react-native-parsed-text/src/ParsedText.js: Unexpected token (23:21)
21 | class ParsedText extends React.Component {
22 |
> 23 | static displayName = 'ParsedText';
| ^
24 |
25 | static propTypes = {
26 | ...React.Text.propTypes,
我的web配置是,
'use strict';
var path = require('path');
var webpack = require('webpack');
var HtmlPlugin = require('webpack-html-plugin');
var HasteResolverPlugin = require('haste-resolver-webpack-plugin');
var IP = '0.0.0.0';
var PORT = 3000;
var NODE_ENV = process.env.NODE_ENV;
var ROOT_PATH = path.resolve(__dirname, '..');
var PROD = 'production';
var DEV = 'development';
let isProd = NODE_ENV === 'production';
var config = {
paths: {
src: path.join(ROOT_PATH, '.'),
index: path.join(ROOT_PATH, 'index.ios'),
},
};
module.exports = {
ip: IP,
port: PORT,
devtool: 'source-map',
resolve: {
alias: {
'react-native': 'react-web',
'ReactNativeART': 'react-art',
},
extensions: ['', '.js', '.jsx'],
},
entry: isProd? [
config.paths.index
]: [
'webpack-dev-server/client?http://' + IP + ':' + PORT,
'webpack/hot/only-dev-server',
config.paths.index,
],
output: {
path: path.join(__dirname, 'output'),
filename: 'bundle.js'
},
plugins: [
new HasteResolverPlugin({
platform: 'web',
nodeModules: ['react-web']
}),
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify(isProd? PROD: DEV),
}
}),
isProd? new webpack.ProvidePlugin({
React: "react"
}): new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
new HtmlPlugin(),
],
module: {
loaders: [{
test: /\.json$/,
loader: 'json'
}, {
test: /\.jsx?$/,
loaders: ['react-hot','babel?stage=1'],
include: [config.paths.src],
exclude: ['/node_modules/', '/node_modules/react-native-gifted-messenger']
},]
}
};
而且我ParseText代碼,
import React from 'react-native';
import TextExtraction from './lib/TextExtraction';
const PATTERNS = {
url: /https?:\/\/(www\.)?[[email protected]:%._\+~#=]{2,256}\.[a-z]{2,6}\b([[email protected]:%_\+.~#?&\/\/=]*)/,
phone: /[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}/,
email: /\[email protected]\S+\.\S+/,
};
const defaultParseShape = React.PropTypes.shape({
...React.Text.propTypes,
type: React.PropTypes.oneOf(Object.keys(PATTERNS)).isRequired,
});
const customParseShape = React.PropTypes.shape({
...React.Text.propTypes,
pattern: React.PropTypes.oneOfType([React.PropTypes.string, React.PropTypes.instanceOf(RegExp)]).isRequired,
});
class ParsedText extends React.Component {
static displayName = 'ParsedText';
static propTypes = {
...React.Text.propTypes,
parse: React.PropTypes.arrayOf(
React.PropTypes.oneOfType([defaultParseShape, customParseShape]),
),
};
您需要啓用[類屬性(https://github.com/jeffmo/es-class-fields-and-static-properties)通過巴貝爾對於語法的工作。這不是標準的ES6。 –
看起來你使用的是舊版本的babel-loader(這取決於babel <6),因爲你有'babel?stage = 1'。如果你實際上使用的是更新版本,那麼'stage'查詢參數將不會做任何事情,在這種情況下,你需要在.babelrc文件中定義預設。 – riscarrott
@bebraw,riscarrott,感謝您的貢獻。答案由 BANANENMANNFRAU在mac平臺上正常工作,但它失敗了,同樣的問題給我在Windows操作系統平臺上。 – Tirth