Skip to content
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

Forbid class fields to fix transpilation errors with Vite/ESBuild #12658

Merged
merged 2 commits into from Apr 14, 2023

Conversation

mourner
Copy link
Member

@mourner mourner commented Apr 13, 2023

Closes #12656, an issue where v2.14 broke building GL JS in some setups involving ESBuild / Vite. The issue was accidentally introduced in #12588 by adding a class field in one place in the source code. In some project setups, this class field introduced a helper method (__publicField), which obviously broke our dynamic main thread / worker bundling setup, where helper functions aren't included in the worker code.

The helper function in turn only appears because of subtle inconsistencies between TypeScript class fields and later developed ECMAScript class fields, defined by the useDefineForClassFields option. This option is turned on by default in Vite, so when GL JS is a part of a bundle with Vite (or ESBuild with this option set), and the target is anything below es2022, it produces a broken bundle.

For now, I'm introducing an ESLint rule to make sure we don't accidentally introduce class fields in our source code, but in the future, we'll need to think of a way to deal with similar problems related to bundling and new syntax.

Launch Checklist

  • briefly describe the changes in this PR
  • write tests for all new functionality
  • manually test the debug page
  • apply changelog label ('bug', 'feature', 'docs', etc) or use the label 'skip changelog'
  • add an entry inside this element for inclusion in the mapbox-gl-js changelog: <changelog>Fix transpilation issues with some setups involving Vite or ESBuild</changelog>

@mourner mourner merged commit a090df0 into main Apr 14, 2023
28 checks passed
@mourner mourner deleted the forbid-class-fields branch April 14, 2023 07:57
mourner added a commit that referenced this pull request Apr 14, 2023
…2658)

* forbid class fields to fix transpilation errors with vite/esbuild

* fix flow
@mourner mourner mentioned this pull request Apr 14, 2023
mourner added a commit that referenced this pull request Apr 14, 2023
* Forbid class fields to fix transpilation errors with Vite/ESBuild (#12658)

* forbid class fields to fix transpilation errors with vite/esbuild

* fix flow

* v2.14.1 version bump + changelog update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Vue3+Vite does not work. Error occurred while parsing the WebWorker bundle.
2 participants