1

I'm reading Learning React by Alex Banks and Eve Porcello, published by O'Reilly Media now and I've received one issue.

From an example, in the book, I can't write this:

enter image description here

because I always receiving this Syntax Error:

enter image description here

Maybe it's the problem with the versions or some loader?

I just can't figure out this by myself.

I'll be very happy to see any reply.

5
  • Maybe this would help, there is a repository of this app ( github.com/MoonHighway/learning-react/tree/master/chapter-06/… ) my code not similar to this, but the issue is the same. Commented Oct 2, 2018 at 11:38
  • It's just a babel config problem, make sure you have -> plugin-syntax-object-rest-spread, if your targeting modern browsers you won't need -> babel-plugin-transform-object-rest-spread, but if you are you will need this too. Commented Oct 2, 2018 at 11:44
  • please provide your webpack.config.js and .babelrc Commented Oct 2, 2018 at 11:44
  • @NguyễnThanhTú , (webpack.config.js) prntscr.com/l18gjx , and .babelrc is just { "presets" : ["env", "react"] } Commented Oct 2, 2018 at 11:51
  • hm, @Keith, thank you for this reply, let me try this. Commented Oct 2, 2018 at 11:51

1 Answer 1

1

Install babel-preset-stage-2 package and try this:

.babelrc

{
  "presets": ["env", "react", "stage-2"]
}
Sign up to request clarification or add additional context in comments.

5 Comments

Wow, you're right. I saw in some articles that this may help, but how this {stage-0, stage-1, stage-2} properly works? Maybe you can suggest some great article to read?
Note that the stage presets are being deprecated in Babel 7 - if you're using that version of Babel, you have to install plugins for individual unstable features you're using. In this case, it would be @babel/plugin-proposal-object-rest-spread. See this blog post for the reasoning behind that.
@Andrew: The blog post I linked may also help you understand why the stage presets existed in the first place :)
@Andrew No worries at all.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.