Defining PropTypes Throws An Error In WebPack

- 1 answer

In my previous React project I was able to define propTypes before my constructor like this

static contextTypes = {
    propToBePassed: React.PropTypes.object.isRequired

But in my new project WebPack is throwing an Unexpected token error with the carrot pointing to the = character.

Any idea what I'm missing?



If you're exporting directly your class declaration and using Babel < 6.2, you'll have to separate it on two different lines like:

import { Component } from 'react'

class Button extends Component {}
export default Button

Depending on your versions, enable the classProperties transform in your Babel options.

You could also look at the transform-class-properties babel docs which tells you to use the babel-plugin-transform-class-properties module like Michelle said.