Jack
Jack

Reputation: 629

Babel compile error on static class properties

I'm using Babel with Webpack in a React demo. The compiling failed on static class properties with functions calls as object value. But fine with plain types.

ERROR in ./src/components/productSet.jsx
Module build failed: SyntaxError: /Users/jack/demo/src/components/productSet.jsx: Unexpected token (9:35)
   7 |     static propTypes: {
   8 |         test: React.PropTypes.object,
>  9 |         data: React.PropTypes.oneOf(['News', 'Photos']),
     |                                    ^
  10 |     }

BTW, I've enable all 0-3 stage features

module: {
    loaders: [{
        test: /.jsx?$/,
        loader: 'babel-loader',
        exclude: /node_modules/,
        query: {
            presets: ['es2015', 'react', 'stage-3', 'stage-2', 'stage-1', 'stage-0']
        }
    }]
},

Upvotes: 0

Views: 817

Answers (1)

Nishanth Matha
Nishanth Matha

Reputation: 6081

Unlike prototypes, The static prototypes should be followed by = not :

try:

static propTypes= { instead of static propTypes: {

Upvotes: 1

Related Questions