Webpack 网页包巴别塔箭头功能模块生成错误

Webpack 网页包巴别塔箭头功能模块生成错误,webpack,ecmascript-6,babeljs,Webpack,Ecmascript 6,Babeljs,我试图在react代码中运行一些arrow函数,但尽管添加了babel加载程序以可读的格式构建代码,我还是在arrow函数的=部分收到了一个错误 export default class CommentForm extends React.Component { constructor(props){ super(props); ... this.state = { value: '', fl

我试图在react代码中运行一些arrow函数,但尽管添加了babel加载程序以可读的格式构建代码,我还是在arrow函数的
=
部分收到了一个错误

export default class CommentForm extends React.Component {
    constructor(props){
        super(props);
        ...
        this.state = {
            value: '',
            flash: '',
            suggestions: [],
        };

        this.onChange = this.onChange.bind(this);
        this.focus = this.focus.bind(this);
    }
    ...
    onChange = (editorState) => {
        this.setState({
            suggestions: ['test']
        });
    }
    ...
}
错误:

ERROR in ./public/components/app/activity-feed/feed/VerticalTimeline/CommentComponents/CommentForm.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: Unexpected token (150:13)
module.exports = {
    mode: 'development',
    entry: "./public/index.js",
    output: {
        path: __dirname + "/dist",
        filename: "bundle.js"
    },
    module: {
        rules: [
            {   
                test: /\.js$/, 
                exclude: /node_modules/, 
                loader: "babel-loader"
            },
            {
                test: /\.css$/,
                use: ['style-loader', 'css-loader'],
            }
        ]
    },
};
  "devDependencies": {
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.2",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    ....
  }
webpack.config.js:

ERROR in ./public/components/app/activity-feed/feed/VerticalTimeline/CommentComponents/CommentForm.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: Unexpected token (150:13)
module.exports = {
    mode: 'development',
    entry: "./public/index.js",
    output: {
        path: __dirname + "/dist",
        filename: "bundle.js"
    },
    module: {
        rules: [
            {   
                test: /\.js$/, 
                exclude: /node_modules/, 
                loader: "babel-loader"
            },
            {
                test: /\.css$/,
                use: ['style-loader', 'css-loader'],
            }
        ]
    },
};
  "devDependencies": {
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.2",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    ....
  }
package.json:

ERROR in ./public/components/app/activity-feed/feed/VerticalTimeline/CommentComponents/CommentForm.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: Unexpected token (150:13)
module.exports = {
    mode: 'development',
    entry: "./public/index.js",
    output: {
        path: __dirname + "/dist",
        filename: "bundle.js"
    },
    module: {
        rules: [
            {   
                test: /\.js$/, 
                exclude: /node_modules/, 
                loader: "babel-loader"
            },
            {
                test: /\.css$/,
                use: ['style-loader', 'css-loader'],
            }
        ]
    },
};
  "devDependencies": {
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.2",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    ....
  }

您正在尝试使用等号定义类属性。这仍然是一个建议,所以它不会开箱即用的巴贝尔。你需要的是一个插件

npm安装——保存dev@babel/plugin提案类属性

//.babelrc
{
  "plugins": ["@babel/plugin-proposal-class-properties"]
}

这个建议的一个很酷的特点是它创建了有界函数。因此,不再需要在构造函数中使用
.bind
!您可以阅读更多信息。

您正在尝试使用等号定义类属性。这仍然是一个建议,所以它不会开箱即用的巴贝尔。你需要的是一个插件

npm安装——保存dev@babel/plugin提案类属性

//.babelrc
{
  "plugins": ["@babel/plugin-proposal-class-properties"]
}

这个建议的一个很酷的特点是它创建了有界函数。因此,不再需要在构造函数中使用
.bind
!您可以阅读更多信息。

FYI如果使用箭头函数语法,则无法将它们绑定到对象。删除
this.onChange=this.onChange.bind(this)在你的构造函数中。谢谢你的回答。我删除了绑定,但仍然收到相同的错误。还有其他建议吗?你的巴别塔配置是什么样子的。babelrc,package.json,无论您将其存放在哪里,
{presets:[“es2015”,“react”]}
,它位于
.babelrc
FYI中。如果您使用箭头函数语法,则无法将它们绑定到对象。删除
this.onChange=this.onChange.bind(this)在你的构造函数中。谢谢你的回答。我删除了绑定,但仍然收到相同的错误。还有其他建议吗?你的巴别塔配置是什么样子的。babelrc,package.json,无论您将其存放在哪里,
{presets:[“es2015”,“react”]}
,它位于
.babelrc