Remove @babel/plugin-proposal-object-rest-spread from default babel configuration
See original GitHub issueIs your proposal related to a problem?
This has been suggested in other issues (notably #5310) and pull requests (#5331). The pull request was closed with the comment:
Unfortunately, I still don’t trust that this works correctly. There’s zero harm in including this plugin to be safe, so let’s leave it for now.
There are a couple of places where this causes “harm”:
- I am declaring Javascript expressions as parameters to higher order components, and these expressions are serialized and sent to the server. The object rest spread babel plugin injects a function call when using the rest operator in these expressions, causing them to fail to be interpreted and validated on the server.
- Perhaps more relevant to more people, transforming this code can cause additional debugging pain. This is not a trivial issue.
The addition of the browsers
option to package.json
is awesome. I’ve been craving a “leave my code the $#@& alone” setting, and setting development mode to latest chrome is almost that, except for the rest operator, and it’s a pain!
Describe the solution you’d like
Remove the inclusion of the @babel/plugin-proposal-object-rest-spread
package by default.
https://github.com/facebook/create-react-app/blob/bffc296a2c8967d46bed40d3120d82f2752496dc/packages/babel-preset-react-app/create.js#L161
Describe alternatives you’ve considered
The obvious workaround is to use Object.assign, but this is an unnecessary restriction and prevents me from using a productive language feature.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
I’ve discovered another subtle and frustrating side effect of this. If you import a CommonJS module from an ES6 module and the CommonJS module contains the object spread operator, the app throws at runtime with the below error:
It’s a pain if you’re sharing modules between node and the browser. Again, the workaround is to use Object.assign, so it’s not the end of the world, but… Rar.
Not sure how relevant this is, but on the babel releases page there appear to have been a few changes to this plugin recently, so removing this would probably coincide with bumping the version of babel we pin. I understand your reasoning, but it’s tough for me to really judge the stability.