Webpack,babel错误:模块构建失败:SyntaxError:意外的令牌

时间:2017-06-25 08:39:17

标签: reactjs webpack babel

在使用webpack编译代码后,在状态之后 = 上面对意外令牌错误。我的代码如下:

class GroceryItem extends React.Component {
    state = {
        labelValue: "Hello Pages"
    };        
    render() {
        return ( < div onClick = {
                this.state.labelValue
            } > ded

            <
            /div>);
        }
    }

我尝试过在StackOverflow上找到的各种方法,但似乎都没有。

.bablerc

{
   "presets" : ["es2015", "react"]
}

.webpack..config.js

var webpack = require('webpack');
var path = require('path');
var BUILD_DIR = path.resolve(__dirname, 'public/js/');
var APP_DIR = path.resolve(__dirname, 'src/components');
var config = {
  entry: APP_DIR + '/main.jsx',
  output: {
  path: BUILD_DIR,
  filename: 'bundle.js'
 },
module : {
    loaders : [
      {
        test : /\.jsx?$/,
        include : APP_DIR,
        loader : 'babel',
        query:{
            presets: ['react']
        }
      }
    ]}
};

module.exports = config;

1 个答案:

答案 0 :(得分:2)

您需要babel-preset-stage-x预设来声明类似的类。 见repl

{
    presets: ["react", "es2015", "stage-2"]

}