Skip to content

Fix create react app builds with es2015 target #1872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 24, 2022

Conversation

reesscot
Copy link
Contributor

@reesscot reesscot commented May 23, 2022

This fixes #1871 by setting the target to es2015

Tested using the following steps:

  1. Edited target to es2018
  2. Ran yarn build
  3. Verified that optional chaining code in use-control.js was tranformed:
        if (!map.hasControl(ctrl)) {
            map.addControl(ctrl, (_a = (opts || onRemove)) === null || _a === void 0 ? void 0 : _a.position);
        }
  1. Copied dist folder to https://github.com/reesscot/react-mapbox-gl-test project's node_modules folder.
  2. Noted that error message around optional chaining in use-control.js went away and got successful build:

image

@Pessimistress
Copy link
Collaborator

See relevant discussion here: #1791 (comment)

The rationale behind the current build target is to allow users to retain the max control of their transpilation. The transform of optional chaining is non reversible. We already have a dist/es5 entry point that is fully transpiled if that is what you wish to target.

Even if we do want to downgrade the build target, is ES2018 not enough?

@reesscot
Copy link
Contributor Author

See relevant discussion here: #1791 (comment)

The rationale behind the current build target is to allow users to retain the max control of their transpilation. The transform of optional chaining is non reversible. We already have a dist/es5 entry point that is fully transpiled if that is what you wish to target.

The es5 entry point doesn’t work for us unless our library users pull all react-map-gl components from the dist/es5 entrypoint. This is difficult as we depend on react-map-gl as a library, and we don't want to force all our users to use the dist/es5 bundle because of a single ES feature (optional chaining).

I understand that rationale to allow users to control their transpilation, but Create React App 4 users don’t have control over transpilation, it’s hidden inside the Webpack config unless you eject. CRA 4 doesn’t transform optional chaining syntax, and is used by a lot of people.

Even if we do want to downgrade the build target, is ES2018 not enough?

I tested out changing the target for react-map-gl to es2018, and that indeed fixes CRA 4 apps. Are you open to changing the target to ES2018?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] es2020 target breaks CRA 4 builds
2 participants