React Not Compiling Spread/Rest Operator

Posted 10 months ago

If you’re facing the error “Module build failed: SyntaxError: Unexpected token” when trying to use the spread operator. Chance are you’re missing the Object rest spread transform which can be found here: https://babeljs.io/docs/en/babel-plugin-transform-object-rest-spread/.

Run:


npm install --save-dev babel-plugin-transform-object-rest-spread

OR


yarn add babel-plugin-transform-object-rest-spread

Then if you don’t already have a .babelrc file, create one with the following.


{
  "plugins": ["transform-object-rest-spread"]
}