javascript – 错误:缺少类属性转换

错误:缺少类属性转换

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”之后.我所做的一切都是.

最佳答案
好的,终于弄清楚了,在我的webpack.config.js我有:

module: {
    loaders: [
      {
        test: /\.js?$/,
        exclude: /(node_modules|bower_components)/,
        loaders: [
          'react-hot',
          'babel?presets[]=react,presets[]=es2015,presets[]=stage-0'
        ]
      }
    ]
  }

‘巴别?预置[] = 0级,预置[] =反应,预置[] = ES2015’

必须以与.babelrc相同的方式对待,将stage-0切换到es2015之后,并且它完美地编译.

转载注明原文:javascript – 错误:缺少类属性转换 - 代码日志