-
Notifications
You must be signed in to change notification settings - Fork 97
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
esbuild serializer causes Gradle to crash when the bundle generates a warning #2416
Comments
After investigating a bit more, those errors are printed by And the same issue also occurs during the iOS build (multi-MB lines printed) but XCode copes well with them and do not crash. |
Do you find the warnings useful? If not, you can suppress them by adding react {
hermesFlags = ["-O", "-output-source-map", "-w"]
} Alternatively, try limiting the line width output: react {
hermesFlags = ["-O", "-max-diagnostic-width=80", "-output-source-map"]
} |
I do not understand where they come from, and did not spend the time trying to figure out why they are here.
Why would those not exist? 🤔 |
Most likely because those functions are polyfilled and Hermes can't see them unless you specify where to look: facebook/hermes#342 You can simply disable the warning if the bundle works without issues. |
One other thing: If you're passing this bundle to the Hermes compiler, you can also consider disabling minification altogether. It shouldn't affect the size of the bytecode output. |
I've just learned that you can control the output width using |
Just to summarize for all the folks seeing crashes/slowdowns when switching to I've submitted a fix upstream to limit the output: facebook/react-native#37531 I will close this issue when it lands. In the meantime, you can apply one of the following workarounds: If you only use Hermes on Android, you can add react {
hermesFlags = ["-O", "-max-diagnostic-width=80", "-output-source-map"]
} Alternatively, if you don't care about the warnings, just disable them: react {
hermesFlags = ["-O", "-output-source-map", "-w"]
} iOS doesn't have an equivalent as far as I can tell. If you also use Hermes on iOS, you can instead disable minifying whitespaces in the esbuild plugin. If you use the esbuild plugin directly in const { makeMetroConfig } = require("@rnx-kit/metro-config");
const { MetroSerializer, esbuildTransformerConfig } = require("@rnx-kit/metro-serializer-esbuild");
module.exports = makeMetroConfig({
serializer: {
customSerializer: MetroSerializer([], {
minify: true,
minifyWhitespace: false, // disable removing whitespace
minifyIdentifiers: true,
minifySyntax: true,
}),
},
transformer: esbuildTransformerConfig,
}); If you use {
...
"rnx-kit": {
...
"bundle": [
{
...
"treeShake": {
"minify": true,
"minifyWhitespace": false,
"minifyIdentifiers": true,
"minifySyntax": true
}
}
]
}
} Either way you configure the plugin, you don't need to change your Documentation: https://github.com/microsoft/rnx-kit/tree/main/packages/metro-serializer-esbuild#minifywhitespace |
Summary: Limit diagnostics width output by `hermesc` as they may cause slowdowns or even crashes in Gradle/Xcode when a minified bundle is used as input. This occurs because Hermes is unable to determine the terminal width when executed by Gradle/Xcode, and falls back to "unlimited". If the input is a minified bundle, Hermes will output the whole bundle for each warning. See issues filed: - microsoft/rnx-kit#2416 - microsoft/rnx-kit#2419 - microsoft/rnx-kit#2424 ## Changelog: [GENERAL] [FIXED] - Limit diagnostics width output by `hermesc` Pull Request resolved: #37531 Test Plan: See listed issues for repros. Reviewed By: cipolleschi Differential Revision: D46102686 Pulled By: cortinico fbshipit-source-id: 1b821cad7ef0d561a5e1c13a7aedf9b10164620a
Merged in facebook/react-native@260bcf7 |
Summary: Limit diagnostics width output by `hermesc` as they may cause slowdowns or even crashes in Gradle/Xcode when a minified bundle is used as input. This occurs because Hermes is unable to determine the terminal width when executed by Gradle/Xcode, and falls back to "unlimited". If the input is a minified bundle, Hermes will output the whole bundle for each warning. See issues filed: - microsoft/rnx-kit#2416 - microsoft/rnx-kit#2419 - microsoft/rnx-kit#2424 ## Changelog: [GENERAL] [FIXED] - Limit diagnostics width output by `hermesc` Pull Request resolved: #37531 Test Plan: See listed issues for repros. Reviewed By: cipolleschi Differential Revision: D46102686 Pulled By: cortinico fbshipit-source-id: 1b821cad7ef0d561a5e1c13a7aedf9b10164620a
What happened?
I configured Metro to use the ESBuild serializer, with the default options.
Using the default
react-native-gradle-plugin
process, Gradle runs the bundle command when building a release, changed so it runsrnx-bundle
:But this happens:
And then the build fails, because the Java process too all available memory trying to output those 5 MB lines.
If I disable whitespace minification in esbuild, then I each error displays the line where it happens, which are short (as there are newline characters in the emitted bundle), and the build goes fine.
Here is the output with whitespace minification disabled:
When I launch the bundle directly from the CLI (
react-native rnx-bundle --dev false --platform android
), those errors are not displayed, so I am not sure what Gradle does that displays them. Could it be a post-process task, done with Metro once the bundle is created?Affected Package
metro-serializer-esbuild
Version
0.1.23
Which platforms are you seeing this issue on?
System Information
Steps to Reproduce
metro-serializer-esbuild
(changing the Metro config is enough, no need for@rnx-kit/cli
here)./gradlew bundleRelease
to generate releaseCode of Conduct
The text was updated successfully, but these errors were encountered: