错误:缺少类属性转换

Error: Missing class properties transform

Test.js

export class Test extends Component {
  constructor (props) {
    super(props)
  }

  static contextTypes = {
    router: React.PropTypes.object.isRequired
  }

.babelrc

{
  "presets": ["es2015", "react", "stage-0"],
  "plugins": ["transform-class-properties"]
}

package.json

"babel-core": "^6.5.1",
"babel-eslint": "^4.1.8",
"babel-loader": "^6.2.2",
"babel-plugin-react-transform": "^2.0.0",
"babel-plugin-transform-class-properties": "^6.5.2",
"babel-preset-es2015": "^6.5.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-0": "^6.5.0",
"babel-register": "^6.5.2",

我在网上搜索了所有修补程序:升级到babel6,将“ stage-0”的顺序切换为“ es2015”之后。我都做了。

Mandy2020/03/23 21:55:18

由于使用env预设,我也遇到此错误: "presets": [ "react", "es2015", "stage-0", ["env", { "modules": false }]], 在删除env预设后,它运行良好

GO2020/03/23 21:55:18

您需要安装babel-plugin-transform-class-properties,即

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

并将以下内容添加到您的.babelrc文件中

"plugins": ["transform-class-properties"] 
十三2020/03/23 21:55:18

我出现此错误是因为我使用stage-3而不是stage-0