Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax error: Rest element must be last element

Getting this error, but unlike other posts I've found on stack overflow, it isn't due to the fact that the spread operator doesn't appear last. In fact, it occurs because of the trailing comma:

const SlashedPrice = ({
    price,
    currencySymbol,
    ...props,
}) => {

When I remove the comma from ...props, the error goes away. At first, I thought this was an issue with babel, but I've included 2 new rules with no luck: "@babel/plugin-proposal-object-rest-spread" and "syntax-trailing-function-commas",

At this point I am at a loss as to what is causing the issue. Where can I begin looking to debug?

Background: Everything in my codebase was working fine, until I removed node_modules and reran yarn install.

like image 255
Tycholiz Avatar asked Oct 30 '19 18:10

Tycholiz


1 Answers

The problem is that, when you let the comma after the ...props, the props isn't the last item anymore. The ...props is the Rest that the error is talking about. It has nothing to do with babel.

Reference here

like image 157
reisdev Avatar answered Nov 12 '22 16:11

reisdev