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

iOS Build with Hermes outputs an incorrect sourcemap file #34212

Closed
louiszawadzki opened this issue Jul 18, 2022 · 1 comment
Closed

iOS Build with Hermes outputs an incorrect sourcemap file #34212

louiszawadzki opened this issue Jul 18, 2022 · 1 comment
Labels
Platform: iOS iOS applications. Tech: Hermes Hermes Engine: https://hermesengine.dev/

Comments

@louiszawadzki
Copy link
Contributor

louiszawadzki commented Jul 18, 2022

Description

When generating a sourcemap file in a build with Hermes enabled in iOS, the generated file is incorrect.

When looking into the build logs from XCode, I realized that the HBC_SOURCEMAP_FILE and PACKAGER_SOURCEMAP_FILE shared the same location (if the SOURCEMAP_FILE is named main.jsbundle.map).

I believe HBC_SOURCEMAP_FILE is not pointing to the right path, as it is in $DEST and not in $CONFIGURATION_BUILD_DIR.

This can be solved in scripts/react-native-xcode.sh if we move the line BUNDLE_FILE="$DEST/main.jsbundle" above the sourcemap composition command, like so:

  "$HERMES_CLI_PATH" -emit-binary $EXTRA_COMPILER_ARGS -out "$DEST/main.jsbundle" "$BUNDLE_FILE"
  BUNDLE_FILE="$DEST/main.jsbundle" # moving the line here works
  if [[ $EMIT_SOURCEMAP == true ]]; then
    HBC_SOURCEMAP_FILE="$BUNDLE_FILE.map"
    "$NODE_BINARY" "$COMPOSE_SOURCEMAP_PATH" "$PACKAGER_SOURCEMAP_FILE" "$HBC_SOURCEMAP_FILE" -o "$SOURCEMAP_FILE"
  fi
  # previous location of the line

I'm ok to open a Pull Request with this change :)
This may be linked to #34043

Version

0.69.0

Output of npx react-native info

System:
OS: macOS 12.4
CPU: (10) arm64 Apple M1 Pro
Memory: 184.34 MB / 32.00 GB
Shell: 5.8.1 - /opt/homebrew/bin/zsh
Binaries:
Node: 18.0.0 - /opt/homebrew/bin/node
Yarn: 1.22.18 - /opt/homebrew/bin/yarn
npm: 8.6.0 - /opt/homebrew/bin/npm
Watchman: 2022.03.21.00 - /opt/homebrew/bin/watchman
Managers:
CocoaPods: 1.11.3 - /Users/louis.zawadzki/.rbenv/shims/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: 2021.1 AI-211.7628.21.2111.8309675
Xcode: 13.4.1/13F100 - /usr/bin/xcodebuild
Languages:
Java: 11.0.15 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 18.0.0 => 18.0.0
react-native: 0.69.0 => 0.69.0
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found

Steps to reproduce

  1. Create a new React Native project
  2. Add a javascript error when clicking on a button
  3. Enable Hermes in the Podfile, run pod install
  4. Add an export SOURCEMAP_FILE=./build/main.jsbundle.map line at the top of the "Bundle React Native code and images" build phase
  5. Build from xcode with Release build configuration
  6. Trigger the error
  7. Symbolicate the error with metro-symbolicate

Snack, code example, screenshot, or link to a repository

Path to sourcemaps files without any change - they are identical:
Capture d’écran 2022-07-18 à 18 53 17

After the change, HBC_SOURCEMAP_FILE points to the right location:
Capture d’écran 2022-07-18 à 18 55 16

@cortinico
Copy link
Contributor

This shoudl be addressed by #34111

@cortinico cortinico added Tech: Hermes Hermes Engine: https://hermesengine.dev/ and removed Needs: Triage 🔍 labels Aug 5, 2022
roryabraham pushed a commit to Expensify/react-native that referenced this issue Aug 17, 2022
…#34111)

Summary:
## Summary

Fixes facebook#32497
Fixes facebook#34212

The assigned HBC_SOURCEMAP_FILE path is incorrect as it does not reference the hermes bundle source map file

See: facebook#32497 (comment)

## Changelog
[General] [Fixed] - using SOURCEMAP_FILE during xcode build phase with Hermes enabled

Pull Request resolved: facebook#34111

Test Plan:
1. In a blank react-native project
1. Enable Hermes
1. Go to xCode -> Project -> Build Phases -> Bundle React Native code and images
3. Add `export SOURCEMAP_FILE="$(pwd)/../ios.jsbundle.map"` before `react-native-xcode.sh`
   e.g.
   ```sh
   export NODE_BINARY=node
   export SOURCEMAP_FILE="$(pwd)/../ios.jsbundle.map"

   ../node_modules/react-native/scripts/react-native-xcode.sh
   ```
4. Make a release build `npx react-native run-ios --configuration Release` or `CMD + I` in xCode
5. Verify the build is successful
6. Verify the `.map` file is outputted at the specified path (`ios.jsbundle.map` in project root for the example above)

Reviewed By: cipolleschi

Differential Revision: D38460586

Pulled By: dmitryrykun

fbshipit-source-id: 54c1594b37fa2253896ce9739c1a9a712deecd0f
roryabraham pushed a commit to Expensify/react-native that referenced this issue Aug 17, 2022
…#34111)

Summary:
## Summary

Fixes facebook#32497
Fixes facebook#34212

The assigned HBC_SOURCEMAP_FILE path is incorrect as it does not reference the hermes bundle source map file

See: facebook#32497 (comment)

## Changelog
[General] [Fixed] - using SOURCEMAP_FILE during xcode build phase with Hermes enabled

Pull Request resolved: facebook#34111

Test Plan:
1. In a blank react-native project
1. Enable Hermes
1. Go to xCode -> Project -> Build Phases -> Bundle React Native code and images
3. Add `export SOURCEMAP_FILE="$(pwd)/../ios.jsbundle.map"` before `react-native-xcode.sh`
   e.g.
   ```sh
   export NODE_BINARY=node
   export SOURCEMAP_FILE="$(pwd)/../ios.jsbundle.map"

   ../node_modules/react-native/scripts/react-native-xcode.sh
   ```
4. Make a release build `npx react-native run-ios --configuration Release` or `CMD + I` in xCode
5. Verify the build is successful
6. Verify the `.map` file is outputted at the specified path (`ios.jsbundle.map` in project root for the example above)

Reviewed By: cipolleschi

Differential Revision: D38460586

Pulled By: dmitryrykun

fbshipit-source-id: 54c1594b37fa2253896ce9739c1a9a712deecd0f
kelset pushed a commit that referenced this issue Jun 8, 2023
Summary:
## Summary

Fixes #32497
Fixes #34212

The assigned HBC_SOURCEMAP_FILE path is incorrect as it does not reference the hermes bundle source map file

See: #32497 (comment)

## Changelog
[General] [Fixed] - using SOURCEMAP_FILE during xcode build phase with Hermes enabled

Pull Request resolved: #34111

Test Plan:
1. In a blank react-native project
1. Enable Hermes
1. Go to xCode -> Project -> Build Phases -> Bundle React Native code and images
3. Add `export SOURCEMAP_FILE="$(pwd)/../ios.jsbundle.map"` before `react-native-xcode.sh`
   e.g.
   ```sh
   export NODE_BINARY=node
   export SOURCEMAP_FILE="$(pwd)/../ios.jsbundle.map"

   ../node_modules/react-native/scripts/react-native-xcode.sh
   ```
4. Make a release build `npx react-native run-ios --configuration Release` or `CMD + I` in xCode
5. Verify the build is successful
6. Verify the `.map` file is outputted at the specified path (`ios.jsbundle.map` in project root for the example above)

Reviewed By: cipolleschi

Differential Revision: D38460586

Pulled By: dmitryrykun

fbshipit-source-id: 54c1594b37fa2253896ce9739c1a9a712deecd0f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Platform: iOS iOS applications. Tech: Hermes Hermes Engine: https://hermesengine.dev/
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants