意外的令牌模块构建失败:SyntaxError

时间:2016-05-10 13:55:19

标签: javascript reactjs react-native webpack webpack-dev-server

我移植GiftedMessager

网络上的

1https://github.com/FaridSafi/react-native-gifted-messenger。 我能够解决previous问题

现在我陷入了新问题,我无法移植 react-native-parsed-text 。在终端窗口找到的错误是

 [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,

我的网络配置是,

'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\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)/,
  phone: /[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}/,
  email: /\S+@\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]),
    ),
  };

1 个答案:

答案 0 :(得分:1)

static关键字仅适用于ES6中的方法。

尝试使用const声明变量。

Source