javascript-reactjs意外令牌’<'

我已经用react-redux,redux创建了reactjs应用程序.
启动reactjs项目时,在索引文件的第13行出现意外的令牌错误.
索引文件位于下面.

ERROR in ./src/index.js
Module build failed: SyntaxError: D:/Reactjs_work/
/src/index.js: Unexpected token (13:2)

  11 |
  12 | ReactDOM.render(
> 13 |   <Provider store={createStoreWithMiddleware(reducers)}>
     |   ^
  14 |     <App />
  15 |   </Provider>
  16 |   , document.querySelector('.container'));

 @ multi main
webpack: Failed to compile.

以下是index.js文件

import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux';

import App from './components/app';
import reducers from './reducers';

const createStoreWithMiddleware = applyMiddleware()(createStore);

ReactDOM.render(
  <Provider store={createStoreWithMiddleware(reducers)}>
    <App />
  </Provider>
  , document.querySelector('.container'));

我在这里经历了以下话题,但没有成功.
Reactjs: Unexpected token ‘<‘ Error
ReactJS Syntax Error: Unexpected Token

webpack.config.js

module.exports = {
  entry: [
    './src/index.js'
  ],
  output: {
    path: __dirname,
    publicPath: '/',
    filename: 'bundle.js'
  },
  module: {
    loaders: [{
      exclude: /node_modules/,
      loader: 'babel'
    }]
  },
  resolve: {
    extensions: ['', '.js', '.jsx']
  },
  devServer: {
    historyApiFallback: true,
    contentBase: './'
  }
};

解决方法:

用以下代码替换模块

module: {
    loaders: [{
      test: /\.(js|jsx)?$/,
        exclude: /node_modules/,
        loader: 'babel-loader',

        query: {
           presets: ['es2015', 'react']
        }
    }]
  },
上一篇:javascript-Reactjs-`component` vs`render`在路线


下一篇:javascript-屏幕导航标题不会显示在堆叠的抽屉导航中…React Navigation V2