3

我正在尝试使用 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

4

1 回答 1

1

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

var MainPage = require('./components/views/app.jsx');
于 2015-07-28T20:18:54.817 回答