reactjs意外的令牌'<'

时间:2017-11-04 10:35:29

标签: javascript reactjs

我用react-redux,redux创建了reactjs应用程序。 当启动reactjs项目时,在索引文件的第13行获得意外的令牌错误。 索引文件是beloow。

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: './'
  }
};

2 个答案:

答案 0 :(得分:3)

用以下代码替换模块

$content = file_get_contents('path_to_file');
//break the content into lines
$lines = explode(PHP_EOL, $content);
//check the lines for the keywords you want
foreach ($lines as $id => $line) {
    if (strpos($line, $keyword) !== false) {
        //remove the line from the array of lines or set it to empty
        $lines[$id] = ""; //or unset($lines[$id]); which ever you prefer
    }
}
$content = implode(PHP_EOL, $lines);
file_put_contents('path_to_file', $content);

答案 1 :(得分:0)

有相同的错误:

ERROR in ./src/main.js
Module build failed: SyntaxError: Unexpected token (11:1)

   9 | 
  10 | ReactDOM.render(
> 11 |  <Provider store={store}>
     |  ^
  12 |      <App />
  13 |  </Provider>,
  14 |  mountNode

 @ multi main
webpack: Failed to compile.

我无助于更改模块部分。

我的错误:.babelrc文件丢失

在创建具有内容的.babelrc之后:

{
    "presets": ["react", "es2015", "stage-0"]
}

我的错误消失了。很简单:-)

相关问题