Help us understand the problem. What is going on with this article?

ReactのJSXでスプレッド属性を使おうとするとsyntax errorが出る対処法

More than 1 year has passed since last update.

Rails5.1のwebpakcerを使って、Reactの勉強をしているのですが、スプレッド属性を使ったときのコンパイルでSyntax errorが出ました。

21:42:08 hot.1  | ERROR in ./app/javascript/packs/hello_react.jsx
21:42:08 hot.1  | Module build failed: SyntaxError: Unexpected token (98:16)
21:42:08 hot.1  |
21:42:08 hot.1  |    96 |
21:42:08 hot.1  |    97 | ReactDOM.render(
21:42:08 hot.1  | >  98 |   <h2 style = {{...myStyle}}>
21:42:08 hot.1  |       |                 ^
21:42:08 hot.1  |    99 |     Let's Spread!
21:42:08 hot.1  |   100 |   </h2>,
21:42:08 hot.1  |   101 |   document.getElementById('container')

何度も確認して記述ミスはなかったのですが、どうやらbabelのpluginが必要みたいでした。

babel-plugin-transform-object-rest-spreadのインストール

$ yarn add babel-plugin-transform-object-rest-spread
  "plugins": [
    "transform-object-rest-spread"
    ]

これだけで治りました。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした