React Routing会产生意外的令牌错误

时间:2015-07-28 19:33:18

标签: javascript reactjs webpack react-router-component

我正在尝试使用react-router-component为我的React应用程序创建路由。但是当我使用webpack构建我的项目时,我收到错误:

ERROR in ./app/js/client.jsx Module build failed: Error: Parse Error: Line 22: Unexpected token <

路由在我的client.jsx文件中,如下所示:

'use strict';

var React = require('react');
var Router = require('react-router-component');
var Locations = Router.Locations;
var Location = Router.Location;
var {MainPage} = require('./components/views/app.jsx');

var App = React.createClass({
  render: function() {
    return (
      <Locations>
        <Location path="/" handler={MainPage} />
      </Locations>
    )
  }
})

React.render(React.createElement(App), document.body)

我不确定我在这里做错了什么。任何帮助,将不胜感激。如果您需要更多信息,请告诉我。谢谢!

编辑:我的webpack配置如下所示:

webpack: {
  client: {
    entry: __dirname + '/app/js/client.jsx',
    output: {
      path: 'build/',
      file: 'bundle.js'
    },
    module: {
      loaders: [
      {
        test: /\.jsx$/,
        loader:'jsx-loader'
      }]
    }
  },
  test: {
    entry: __dirname + '/test/client/test.js',
    output: {
      path: 'test/client/',
      file: 'bundle.js'
    },
    module: {
      loaders: [
      {
        test: /\.jsx$/,
        loader:'jsx-loader'
      }]
    }
  },
  karma_test: {
    entry: __dirname + '/test/karma_tests/test_entry.js',
    output: {
      path: 'test/karma_tests/',
      file: 'bundle.js'
    },
    module: {
      loaders: [
      {
        test: /\.jsx$/,
        loader:'jsx-loader'
      }]
    },
    background: true
  }
},

您可以在此处查看完整项目:https://github.com/mrbgit/short-stories/tree/add-category-age

1 个答案:

答案 0 :(得分:1)

不要对MainPage变量使用解构,因为该文件只导出React类。看起来应该是这样的

var MainPage = require('./components/views/app.jsx');