【问题标题】:Module build failed: SyntaxError: Unexpected token (10:40) react fixed data table模块构建失败:SyntaxError: Unexpected token (10:40) react fixed data table
【发布时间】:2017-06-18 11:49:16
【问题描述】:

我们有一个带有这个OurController 项目的反应应用程序。 OurController 工作正常。从示例中添加以下代码会破坏整个应用程序,不会在浏览器中呈现任何页面:

const TextCell = ({rowIndex, data, col, ...props}) => (
  <Cell {...props}>
    {data.getObjectAt(rowIndex)[col]}
  </Cell>
);

文件的开头是

var FixedDataTable = require('fixed-data-table');
var React = require('react');

const Table = FixedDataTable.Table;
const Column = FixedDataTable.Column;
const Cell = FixedDataTable.Cell;

const TextCell = ({rowIndex, data, col, ...props}) => (
  <Cell {...props}>
    {data.getObjectAt(rowIndex)[col]}
  </Cell>
);

class OurDataTable extends React.Component {

一旦我将其注释掉,一切都很好,但我想尽可能地遵循教程

错误是这样的

Module build failed: SyntaxError: Unexpected token (10:40)
const TextCell = ({rowIndex, data, col, {issue is here}...props}) => (

带有指向...props的箭头,好像看不懂...(箭头指向第一个点)

指南是fixed-data-table的这个sn-p:

https://github.com/facebook/fixed-data-table/blob/master/examples/ObjectDataExample.js

我知道整个文件通常很重要,但我保证代码会按预期工作,直到添加 TextCell。我们有某些 babel loader,但我没有看到固定数据表要求更多:

var webpack = require('webpack');

module.exports = {
  //devtool: 'inline-source-map',
  entry: [
    'webpack-hot-middleware/client',
    './client/main.js'
  ],
  output: {
    path: require("path").resolve('./public'),
    filename: 'bundle.js',
    publicPath: '/'
  },
  plugins: [
    new webpack.HotModuleReplacementPlugin()
  ],
  module: {
    loaders: [
      {
        test: /\.jsx?$/,
        loader: 'babel-loader',
        exclude: /node_modules/,
        query: {
          presets: ['react', 'es2015', 'react-hmre']
        }
      }
    ]
  }
};

一个快速服务器同样配置并且正在工作(热重载等)

我们已经使用了 ES6 并且在类似的东西上工作

class OurDataTable extends React.Component {

【问题讨论】:

    标签: javascript html facebook reactjs fixed-data-table


    【解决方案1】:

    不确定,但我认为,问题在于扩展运算符...,您需要配置Babel 才能使用transform-object-rest-spread plugin

    点击此链接进行安装:https://babeljs.io/docs/plugins/transform-object-rest-spread/

    【讨论】:

    • 繁荣,认为这是一些奇怪的装载机。谢谢 Mayank 我检查了
    猜你喜欢
    • 2018-06-09
    • 1970-01-01
    • 2017-12-06
    • 2016-04-09
    • 1970-01-01
    • 2017-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多