question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Remove @babel/plugin-proposal-object-rest-spread from default babel configuration

See original GitHub issue

Is 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:open
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
danderson00commented, Oct 12, 2019

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:

Attempted import error: ‘./path’ does not contain a default export (imported as ‘name’)

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.

1reaction
heyimalexcommented, Aug 5, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use the babel-plugin-transform-react-remove-prop ...
To help you get started, we've selected a few babel-plugin-transform-react-remove-prop-types.default examples, based on popular ways it is used in public ...
Read more >
Options - Babel.js
Defaults to searching for a default babel.config.json file, but can be passed ... Note: This option may be removed in future Babel versions...
Read more >
Plugins - Babel.js
Babel's code transformations are enabled by applying plugins (or [presets](/docs/en/presets)) to your [configuration file](/docs/en/config-files).
Read more >
Upgrade to Babel 7
For monorepos we have added a new babel.config.js file that centralizes our ... We are removing the stage presets in favor of explicit...
Read more >
babel/plugin-proposal-object-rest-spread
By default, this plugin will produce spec compliant code by using Babel's objectSpread helper. loose. boolean , defaults to false . Enabling this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found