0
ERROR in ./src/js/HomeView.js
Module build failed: SyntaxError: Unexpected token (122:19)

  120 |   }
  121 | 
> 122 |   handleDrawerOpen = () => {
      |                    ^
  123 |     this.setState({ open: true });
  124 |   };
  125 | 

Got the above error when trying to compile react component using webpack. Does anyone know what is the missing plugin here?

1
  • Can I see the full source including that part? Commented Dec 18, 2017 at 9:56

2 Answers 2

1

You'll probably need to install preset-stage-2. This babel plugin allows you to use ES6+ features such as statics, property initializers, and even dynamic import support. You could actually just install transform-class-properties for this particular case, but I usually prefer to install a babel plugin with stage-x because I find it comfortable to use multiple ES6+ features with a single install. It might also be useful to future readers that this particular Babel plugin is already properly set up for you if you use create-react-app, as you can check here.

Sign up to request clarification or add additional context in comments.

4 Comments

Mind to explain why that is needed?
this is called property initializers and they are part of ES7 standard. to enable them in ES5/ES6 environments, you need to use a transpiler with proper settings. you can read more here
@Mox I'm editing right now, sorry but I usually prefer to give a brief answer and then provide more details in the next hour or two.
Also, you'll find further infos in the link embedded into my answer
0

Difficult to guess from the code you have pasted above.

My guess is change it to

handleDrawerOpen() {
    this.setState({ open: true });
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.