-
Notifications
You must be signed in to change notification settings - Fork 100
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
metro-serializer-esbuild: "Transforming generator functions to the configured target environment ("es5") is not supported yet" #1743
Comments
Thank you for filing this @jamonholmgren! I will explain what is going on, and then defer to @tido64 to decide what we can do about it. Why is this happening?We use esbuild to make tree shaking work with Metro. We configure esbuild to target an "es5" runtime environment to ensure that we're compatible with Hermes. Hermes doesn't fully support es6 yet. Esbuild doesn't fully support transpiling down to "es5", though. See here:
So this puts you in a bind. Effectively, you have to write your code in es5 for our tree shaking solution to work as it stands today. What about ES6?I tried changing the esbuild target to es6 (by hand, in node_modules) and it works just fine. es6 bundle is made. Ignite sample app loads it just fine (after a bit of hacking to make debug builds load from a file). Why can't I use ES6? I don't care about Hermes.This is where @tido64 comes in. Should we expose a "target" option in the tree shaking config? e.g. "hermes" (implies es5), "es6", and maybe "esnext"? Whatever is decided, we need to update the README and the guides which cover tree shaking to explain this limitation, what it looks like when you run into it, and how to work around it (or if you have to bail on the whole thing). |
Thank you @afoxman! I unfortunately do care about Hermes, as we are intending to turn it on by default in future Ignite releases. Follow-up question: is the Hermes incompatibility with ES6 just some random edge cases, or is it a blocker? Studying the linked issue(s), it's hard to tell. Secondly: could we transpile from esnext to ES5 after running esbuild, using Babel? So Babel would re-transpile the esbuild output to ES5, and that could be configurable if Hermes is enabled. |
For (1), @tido64 will know. For (2), I don't know how well it would work to transpile the whole bundle after-the-fact. Why not do it earlier, during the Metro run, via a babel plugin? I was able to get something working using this: presets: [
+ ["@babel/preset-env", { loose: true }],
["@rnx-kit/babel-preset-metro-react-native", { unstable_transformProfile: "esbuild" }],
], You will need to pass I am a Babel Novice, so while this no longer makes esbuild/tree shaking upset, it may be doing horrible things to the bundle. But it demonstrates the approach, and from here, I'd consult a Babel Sage for more advice. I did test it with the Ignite sample app, and things worked. |
As Adam mentioned, Hermes only implements selected ES6 features and lacks basic things like blocked-scope variables. If you want more details, I suggest you reach out to the Hermes folks on Discord. As for providing module.exports = makeMetroConfig({
projectRoot: __dirname,
serializer: {
+ customSerializer: MetroSerializer([], { target: "es5" }),
},
transformer: esbuildTransformerConfig,
}); As of esbuild 0.14.49, you can also do: module.exports = makeMetroConfig({
projectRoot: __dirname,
serializer: {
+ customSerializer: MetroSerializer([], { target: "hermes0.70.0" }),
},
transformer: esbuildTransformerConfig,
}); I haven't tested with |
Submitted a PR to document options. Also, I wouldn't use |
Created a WIP PR to track over on Ignite (infinitered/ignite#1984). |
That's awesome! Keep us posted. Also, FYI: #1761 |
These are my thoughts about this topic:
Clone the repo urban-enigma TEST 1
TEST 2
|
As far as I know, it's due to this line in
|
@tido64 the
Test plan
+ supported: {
+ generator: true,
+ }
🙏 hope that this help! I think that the best way to go here is use `es6` as a `target` and add the supported and unsupported features:supported: {
// Hermes only supports these ES6 features.
arrow: true,
"array-spread": true,
"default-argument": true,
destructuring: true,
"for-of": true,
generator: true,
"object-accessors": true,
"object-extensions": true,
"object-rest-spread": true,
"optional-catch-binding": true,
"optional-chain": true,
"rest-argument": true,
"template-literal": true,
"logical-assignment": true,
"nullish-coalescing": true,
"nested-rest-binding": true,
// Hermes doesn't support these ES6 features (needs more investigation).
"arbitrary-module-namespace-names": false,
"async-await": false,
"async-generator": false,
bigint: false,
class: false,
"class-field": false,
"class-private-accessor": false,
"class-private-brand-check": false,
"class-private-field": false,
"class-private-method": false,
"class-private-static-accessor": false,
"class-private-static-field": false,
"class-private-static-method": false,
"class-static-blocks": false,
"class-static-field": false,
"const-and-let": false,
"dynamic-import": false,
"exponent-operator": false,
"export-star-as": false,
"for-await": false,
hashbang: false,
"import-assertions": false,
"import-meta": false,
"new-target": false,
"node-colon-prefix-import": false,
"node-colon-prefix-require": false,
"regexp-dot-all-flag": false,
"regexp-lookbehind-assertions": false,
"regexp-match-indices": false,
"regexp-named-capture-groups": false,
"regexp-sticky-and-unicode-flags": false,
"regexp-unicode-property-escapes": false,
"top-level-await": false,
"typeof-exotic-object-is-object": false,
"unicode-escapes": false,
}, |
@ecreeth Thanks for the help. I was merely referring to why there is a diff when targeting Hermes, but I guess I left out the context 😆 In any case, I've submitted a PR to re-enable the features that are safe to include. I looked through the others that are partially implemented and I have decided not to enable them to avoid surprises. |
What happened?
I'm currently trying out
@rnx-kit/metro-serializer-esbuild
on Ignite and running into the following error:Current diff: https://github.com/infinitered/ignite/compare/rnx-kit-esbuild
I can't figure out where the target is configured for esbuild so I can change it to
esnext
or similar. Ideas?Affected Package
@rnx-kit/metro-serializer-esbuild
Version
0.1.9
Which platforms are you seeing this issue on?
System Information
The text was updated successfully, but these errors were encountered: