React Not Compiling Spread/Rest Operator

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:


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


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"]

Categories: JavascriptReact