【问题标题】:How to fix 'Module build failed: SyntaxError: Missing class properties transform.'?如何修复“模块构建失败:语法错误:缺少类属性转换。”?
【发布时间】:2017-11-23 17:31:40
【问题描述】:

在我的 reactjs 组件中,我有以下代码:

increment = () => {
     store.dispatch({type: 'INC'});
}

当我在控制台中运行 npm start 时,我得到:

Module build failed: SyntaxError: Missing class properties transform.

我安装了:

npm install --save-dev babel-plugin-transform-class-properties

并将其添加到我的 .babelrc 中:

  "plugins": [
    "transform-class-properties"
  ],

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

我该如何解决这个问题?

【问题讨论】:

  • 你的npm start脚本的内容是什么?
  • webpack-dev-server --progress --inline --hot

标签: javascript reactjs webpack babeljs


【解决方案1】:

你看过这个其他帖子吗:Error: Missing class properties transform

我遇到了类似的问题,并且正如上面接受的答案中的一个 cmets 所暗示的那样,我的 .babelrc 文件和 webpack.config 中都列出了预设。我从 webpack.config 中删除了多余的选项,现在它运行了。

【讨论】:

    猜你喜欢
    • 2018-05-28
    • 2016-06-01
    • 2018-07-11
    • 1970-01-01
    • 2020-11-18
    • 1970-01-01
    • 1970-01-01
    • 2022-12-19
    • 1970-01-01
    相关资源
    最近更新 更多