-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
Bundling React Native with Hermes manually #34043
Comments
Hey hey @marandaneto 👋
Yes those commands are correct (are the same we're generating during an app build).
Yes you are.
Not that I'm aware. It's going to change in 0.69.x though. The significant change is that the path of hermesc will change:
Sadly the docs on this are scarce as we don't expect users to manually generate sourcemaps. |
@cortinico Hey hey :) Awesome, thank you for letting me know the So the question is: if we're using the right commands and uploading the files correctly. Thanks a lot for keeping improving React Native :) |
I would suggest to try to verify that the source map is valid first.
Also is this issue happening only for Hermes? |
On Android, I've noticed that you have to upload the output ( On iOS, it does not work at all, stack trace and line numbers still don't match. I've noticed that the output of the command 1 ( Again, if you don't bundle yourself, everything works as expected. |
@marandaneto So just generate source-maps using npx react-native bundle --platform ios --dev false --entry-file index.js --reset-cache --bundle-output main.jsbundle --sourcemap-output main.jsbundle.packager.map --minify false Then you can check some stack traces locally to verify they are getting decoded npx metro-symbolicate main.jsbundle.packager.map < ios.stacktrace.txt Hermes for iOS is enabled (react-native 0.66.4) I don't know why but combining the packager and the hbc source maps results it E.g. npx metro-symbolicate main.jsbundle.map < ios.stacktrace.txt
0 ??? 0x0 shouldComponentUpdate + 199284 (null:null:null)
1 ??? 0x0 checkShouldComponentUpdate + 5581 (null:null:null)
2 ??? 0x0 updateClassComponent + 6842 (null:null:null) While using just the npx metro-symbolicate main.jsbundle.packager.map < ios.stacktrace.txt
0 ??? 0x0 shouldComponentUpdate + 199284 ([redacted]\src\pages\home\report\ReportActionsView.js:114:constructor)
1 ??? 0x0 checkShouldComponentUpdate + 5581 ([redacted]\node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-prod.js:2527:checkShouldComponentUpdate)
2 ??? 0x0 updateClassComponent + 6842 ([redacted]\node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-prod.js:4461:updateClassComponent)
3 |
@kidroca awesome, let me try this workaround, thanks. |
It didn't work for me on iOS, RN |
From the looks of it the manual setup that uses react-native's own export NODE_BINARY=node
export EXTRA_PACKAGER_ARGS="--sourcemap-output $DERIVED_FILE_DIR/main.jsbundle.map"
export SENTRY_PROPERTIES=../sentry.properties
../node_modules/@sentry/cli/bin/sentry-cli react-native xcode \
../node_modules/react-native/scripts/react-native-xcode.sh
To make a combined map automatically through the build phase we need to react-native/scripts/react-native-xcode.sh Lines 125 to 128 in 4ea38e1
Which then instructs the script to make 2 maps (if using Hermes) and combine them, but for some reason the combined map doesn't work to decode stack traces, only the packager map works. Perhaps something goes wrong while the maps are merged because the combined map size is smaller than any of the two maps, I'd expect it'll be as big as the two maps combined |
If I |
So on iOS, we're using the If I upload the bundle and this |
What I'm trying to say is because of these packager args, the generated export EXTRA_PACKAGER_ARGS="--sourcemap-output $DERIVED_FILE_DIR/main.jsbundle.map" If that works for you, you can generate the same manually npx react-native bundle --platform ios --dev false --entry-file index.js --reset-cache --bundle-output main.jsbundle --sourcemap-output main.jsbundle.packager.map --minify false I'm working on decoding js stacktraces from Firebase Crashlytics and tried this in both existing and a new RN project |
@kidroca Yep, I understood what you meant, still, output is the same, line numbers are all wrong. |
Btw what you said, the file |
Can you diff the 2 outputs?
Depending on whether you've touched the build phase there might be no source map comment at all |
@kidroca that was the trick, this comment is likely used within the symbolication process or within the file itself.
Setting the Or just set the file name correctly in command 1 for iOS:
Thanks @kidroca |
So for you - you had to have both files named For me, though, it seems I can name the sourcemap output to anything, this just works: npx metro-symbolicate my-ios-map-file.map < ios.cralyitics.stacktrace.txt |
I'm having an issue even getting the bundle to run on Android. I've created a script to handle this:
This looks the same to me as what's recommended here (albeit with a different directory). When I try and open up the resulting .apk, I get Has anyone else seen this? EDIT: I think perhaps I misunderstood here. I think the outputted bytecode bundle is just to be uploaded to sentry, not to actually be used in the .apk. So I need to output this somewhere else. |
I didn't investigate deeply, but now, Android and iOS with hermes work well without any RN: 0.71.2 |
Is it possible that the source maps work without I've created a new app using This was changed in |
Yes, also, it works well not only in the binary release but also code push release (Android, iOS both and both are using Hermes).
I bundled assets manually(2) because, appcenter cli is using I can't sure why this works, but it shows the correct stack trace in Sentry with code push release. run: npm install -g appcenter-cli
// 1
appcenter codepush release-react -a {{Your Project}} -d {{Deployment}} -t {{Target Binary Version}} --token {{ Your TOKEN }}
// 2
node node_modules/.bin/react-native bundle --platform ios --dev false --entry-file index.js --bundle-output main.jsbundle --sourcemap-output main.jsbundle.map
node_modules/@sentry/cli/bin/sentry-cli releases files {{ Your Release }} upload-sourcemaps --dist {{ Your dist }} main.jsbundle main.jsbundle.map |
I did some more testing and this is what I've found. Hermesc If hermes byte code bundle is generated without a source map the packager source map will work. If hermes byte code bundle is generated with the source map the combined source map will work. ❯ hermesc -O -emit-binary -output-source-map -out=main.jsbundle.hbc.with.source.maps main.jsbundle
❯ ls -lh main.jsbundle.hbc.with.source.maps
-rw-r--r-- 1 krystofwoldrich staff 1.6M Mar 29 10:36 main.jsbundle.hbc.with.source.maps
❯ hermesc -O -emit-binary -out=main.jsbundle.hbc.without.source.maps main.jsbundle
❯ ls -lh main.jsbundle.hbc.without.source.maps
-rw-r--r-- 1 krystofwoldrich staff 2.1M Mar 29 10:36 main.jsbundle.hbc.without.source.maps |
@krystofwoldrich This seems to be true. Recently, I bundled manually with sourcrmap and it didn't cause any error with combine sourcemap script(Android). And it works in sentry stacktrace. In past, I didn't generate sourcemap in bundling process. |
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
Hello! I'm having same issue with upload manually. Any update? |
Description
I'd like to generate the bundles of an RN App with Hermes enabled manually, so I could upload them manually to 3rd tools such as Sentry.io in order to symbolicate stack traces.
I've not found official documentation about that so I've tried to do reverse engineering myself.
Linked issue getsentry/sentry-react-native#2244
Sentry's docs: https://docs.sentry.io/platforms/react-native/manual-setup/hermes/
Version
0.67.4
Output of
npx react-native info
System:
OS: macOS 12.4
CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 132.30 MB / 32.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 18.3.0 - /usr/local/bin/node
Yarn: 1.22.19 - ~/.yarn/bin/yarn
npm: 8.11.0 - /usr/local/bin/npm
Watchman: 2022.06.13.00 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.11.3 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5
Android SDK: Not Found
IDEs:
Android Studio: Chipmunk 2021.2.1 Patch 1 Chipmunk 2021.2.1 Patch 1
Xcode: 13.4.1/13F100 - /usr/bin/xcodebuild
Languages:
Java: 11.0.10 - /Users/user/.sdkman/candidates/java/current/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 17.0.2 => 17.0.2
react-native: 0.67.4 => 0.67.4
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found
Steps to reproduce
If I do it on Android:
cd android
Bundle: android/app/build/generated/assets/react/release/index.android.bundle
Bundle.map: android/app/build/generated/sourcemaps/react/release/index.android.bundle.map
Everything works as expected, in this case, I'm using the generated bundles by the RN tooling.
If I do it on iOS:
In this case, I've generated the bundles myself, now I have to upload it:
sentry-cli releases files $release upload-sourcemaps --dist $dist --strip-prefix $fullRootFolder main.jsbundle main.jsbundle.map
See screenshots in the
Snack, code example, screenshot, or link to a repository section
.So my question is:
Am I using the right commands with the right parameters?
npx react-native bundle
,hermesc
andcompose-source-maps.js
?Am I uploading the right files?
Did this behavior change across RN versions? such as
0.63.x
-0.68.x
?Is there any official documentation around generating bundles manually with Hermes?
Thanks a bunch.
Snack, code example, screenshot, or link to a repository
How it is:
How it should be:
The text was updated successfully, but these errors were encountered: