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, Xcode] Automatic source map upload is not working in RN 0.75.x #4074

Closed
LydGol90 opened this issue Sep 9, 2024 · 22 comments
Closed

[iOS, Xcode] Automatic source map upload is not working in RN 0.75.x #4074

LydGol90 opened this issue Sep 9, 2024 · 22 comments

Comments

@LydGol90
Copy link

LydGol90 commented Sep 9, 2024

Important

To fix the automatic upload in 0.75 please add the following to your Bundle React Native code and image Build Phase:

set -e

+export BUNDLE_COMMAND="bundle"

WITH_ENVIRONMENT="$REACT_NATIVE_PATH/scripts/xcode/with-environment.sh"
REACT_NATIVE_XCODE="$REACT_NATIVE_PATH/scripts/react-native-xcode.sh"

/bin/sh -c "$WITH_ENVIRONMENT \"/bin/sh ../node_modules/@sentry/react-native/scripts/sentry-xcode.sh >$REACT_NATIVE_XCODE\""

For more detail see #4074 (comment)

Description

Hi there,

I am having trouble with ios source maps.

I followed the manual set up here:
https://docs.sentry.io/platforms/react-native/manual-setup/manual-setup/

I added SOURCEMAP_FILE as RN docs imply that is required to enable sourcemaps at all for ios
https://reactnative.dev/docs/debugging-release-builds#enabling-source-maps

This is my "Bundle React Native code and images" script:

export SOURCEMAP_FILE="$DERIVED_FILE_DIR/main.jsbundle.map";
export SOURCE_MAP_PATH="$DERIVED_FILE_DIR/main.jsbundle.map";

set -e

WITH_ENVIRONMENT="../node_modules/react-native/scripts/xcode/with-environment.sh"
REACT_NATIVE_XCODE="../node_modules/react-native/scripts/react-native-xcode.sh"
SENTRY_XCODE="../node_modules/@sentry/react-native/scripts/sentry-xcode.sh"
BUNDLE_REACT_NATIVE="/bin/sh $SENTRY_XCODE $REACT_NATIVE_XCODE"

/bin/sh -c "$WITH_ENVIRONMENT \"$BUNDLE_REACT_NATIVE\""

I have a sentry.properties file at the correct location.

I also added the script for "Upload Debug Symbols to Sentry"

This is what I see in Sentry for a JS crash:
Image
Image

Are there additional steps that I am missing? I see there is more documentation around Hermes and around using the fastlane plugin but I'm not clear if those are additional steps or alternative steps.

react-native info:

  OS: macOS 14.6.1
  CPU: (12) arm64 Apple M2 Max
  Memory: 101.63 MB / 32.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.10.0
    path: ~/.nvm/versions/node/v20.10.0/bin/node
  Yarn:
    version: 1.22.19
    path: ~/.nvm/versions/node/v20.10.0/bin/yarn
  npm:
    version: 10.2.3
    path: ~/.nvm/versions/node/v20.10.0/bin/npm
  Watchman:
    version: 2024.01.22.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.14.3
    path: /Users/lydiagolland/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.5
      - iOS 17.5
      - macOS 14.5
      - tvOS 17.5
      - visionOS 1.2
      - watchOS 10.5
  Android SDK: Not Found
IDEs:
  Android Studio: 2024.1 AI-241.18034.62.2412.12266719
  Xcode:
    version: 15.4/15F31d
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.10
    path: /opt/homebrew/opt/openjdk@17/bin/javac
  Ruby:
    version: 3.1.4
    path: /Users/lydiagolland/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.75.2
    wanted: 0.75.2
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

FYI I followed the android instructions from the same docs and that is all working fine.

Many thanks for any help!

@krystofwoldrich
Copy link
Member

Hi @LydGol90,
thank you for the message,

have you included @sentry/react-native/metro in your metro.config.js?

https://docs.sentry.io/platforms/react-native/manual-setup/metro/#use-sentry-metro-serializer

This will ensure the Metro Bundler is generating the Debug IDs.

@LydGol90
Copy link
Author

LydGol90 commented Sep 11, 2024

Hi @krystofwoldrich, thank you for your reply. Yes sorry, I should have included that in my original message, I have added that as per the docs.

@krystofwoldrich
Copy link
Member

Hi,
thank you for the clarification.

Please upgrade to the latest SDK,

this issue was caused by a bug in Sentry CLI which caused background uploads to fail.

As a workaround you can also force foreground uploads as described in.

@LydGol90
Copy link
Author

LydGol90 commented Sep 16, 2024

@krystofwoldrich Thanks for your reply. I have upgraded to 5.32.0, however I am still seeing the same issue. I have Hermes enabled, is there any additional configuration I am missing?

If helpful, under the "Source Maps" section under settings for my project I am just never seeing any artifacts uploaded, under the "Debug Files" section I am.

Thanks

@skogby
Copy link

skogby commented Sep 16, 2024

Hey, we also have a similar/same issue, using sentry/[email protected] and [email protected].
Looking into the build-log I can see the following message:

output: sentry-cli - + [[ true == true ]]
output: sentry-cli - + HBC_SOURCEMAP_FILE=/Users/.../Release-iphoneos/App.app/main.jsbundle.map
output: sentry-cli - + /Users/.../node_modules/@sentry/cli-darwin/bin/sentry-cli /Users/.../node_modules/react-native/scripts/compose-source-maps.js /Users/.../Release-iphoneos/main.jsbundle.map /Users/.../Release-iphoneos/App.app/main.jsbundle.map -o /Users/.../Release-iphoneos/App.build/DerivedSources/main.jsbundle.map
output: sentry-cli -   WARN    2024-09-16 15:38:02.798956 +02:00 Failed to load .env file: Error parsing line: 'App', error at line index: 12
output: sentry-cli - No packager source map found in source map report, skipping copy of debug id to Hermes combined source map.
output: sentry-cli - + rm /Users/.../Release-iphoneos/App.app/main.jsbundle.map
output: sentry-cli - + rm /Users/.../Release-iphoneos/main.jsbundle.map
output: sentry-cli - + BUNDLE_FILE=/Users/.../Release-iphoneos/App.app/main.jsbundle
output: sentry-cli - + [[ false != true ]]
output: sentry-cli - + [[ ! -f /Users/.../Release-iphoneos/App.app/main.jsbundle ]]
output: sentry-cli - Warning: build produced no packager sourcemaps.

I can also see that SOURCEMAP_FILE is set some lines above...

We updated from [email protected] and sentry/[email protected] last week, and it was working at that time.
Thank you!

@LydGol90
Copy link
Author

LydGol90 commented Sep 17, 2024

@skogby Thanks for your help, my issues also started after an RN upgrade - perhaps the sourcemaps are not being generated correctly in RN 0.75.

@skogby
Copy link

skogby commented Sep 19, 2024

@krystofwoldrich I think this is still an issue:
As Sentry debug symbol upload is blocking us from updating to react-native 0.75.X at the moment I did some debugging, and I can see that the change made here:
facebook/react-native@eba1828#diff-16a358d6a9dea8469bfdb899d0990df1c32b8c3b1149c86685bec81f50bd24beR150 is what is causing the issue.
I can also see that react-native has updated the packages/react-native/scripts/react-native-xcode.sh after latest release and if I copy-paste the raw source into my node-modules folder it starts working again. Seems like the sentry-cli is not managing to find the debug files in react-native 0.75.
I am using export SENTRY_CLI_EXTRA_ARGS="--force-foreground" in .xcode.env just to be sure (and "@sentry/react-native": "~5.32.0")

@christianbach
Copy link

@skogby we are seeing the exact same issue in our build with RN 0.75.3

2024-09-21T12:36:15.0957250Z output: sentry-cli - No packager source map found in source map report, skipping copy of debug id to Hermes combined source map.
...
2024-09-21T12:36:15.0963160Z output: sentry-cli - Warning: build produced no packager sourcemaps.

We are running version 5.33.0 of @sentry/react-native

Tried the workaround:
export SENTRY_CLI_EXTRA_ARGS="--force-foreground"

But with the same results, no source maps...

@christianbach
Copy link

@skogby did you ever resolve the issue? This is still a problem for us.

@LydGol90
Copy link
Author

@krystofwoldrich Would it be possible to reopen this issue to investigate the above? Seems that the latest SDK is not working with RN 0.75.X specifically. Many thanks

@skogby
Copy link

skogby commented Sep 25, 2024

@christianbach I used yarn patch to patch react-native dependency and changed the packages/react-native/scripts/react-native-xcode.sh script so it is exactly as it is on master branch right now, and then it started working.

@ridvanaltun
Copy link

@krystofwoldrich Would it be possible to reopen this issue to investigate the above? Seems that the latest SDK is not working with RN 0.75.X specifically. Many thanks

I think it should be reopened

@skogby
Copy link

skogby commented Sep 26, 2024

I opened a new issue, as the Sentry crew probably don't look into closed issues. #4120

@christianbach
Copy link

christianbach commented Sep 26, 2024

@christianbach I used yarn patch to patch react-native dependency and changed the packages/react-native/scripts/react-native-xcode.sh script so it is exactly as it is on master branch right now, and then it started working.

@skogby Great and thanks for the clarification!

@krystofwoldrich
Copy link
Member

Hello, everyone, thank you for all the messages and excuse the long waiting time.

I returned from my time off and looking into this right now.

@krystofwoldrich
Copy link
Member

krystofwoldrich commented Oct 2, 2024

The automatic upload of source maps during Xcode builds to Sentry uses the CLI_PATH and BUNDLE_COMMAND variables used by the react-native-xcode.sh.

The CLI_PATH and BUNDLE_COMMAND variable were removed in RN 0.75 (facebook/react-native@eba1828#diff-16a358d6a9dea8469bfdb899d0990df1c32b8c3b1149c86685bec81f50bd24be) and without them the Sentry CLI is unable to automatically detect the path to the JS bundle and source map.


The removal of CLI_PATH variable was reverted in facebook/react-native@aa4f802 (for 0.76) and in facebook/react-native@88276c5 for (for 0.75).

But Sentry CLI also requires BUNDLE_COMMAND which default value was not restored.

To fix the automatic upload in 0.75 please add the following to your Bundle React Native code and image Build Phase:

set -e

+export BUNDLE_COMMAND="bundle"

WITH_ENVIRONMENT="$REACT_NATIVE_PATH/scripts/xcode/with-environment.sh"
REACT_NATIVE_XCODE="$REACT_NATIVE_PATH/scripts/react-native-xcode.sh"

/bin/sh -c "$WITH_ENVIRONMENT \"/bin/sh ../node_modules/@sentry/react-native/scripts/sentry-xcode.sh $REACT_NATIVE_XCODE\""

@krystofwoldrich
Copy link
Member

The BUNDLE_COMMAND default value was returned in facebook/react-native#46495, facebook/react-native@afd74ad (for 0.75) and in facebook/react-native@efc475c (for 0.76).

In the upcoming RN 0.75.4 the iOS auto upload will work out of the box.

@krystofwoldrich krystofwoldrich changed the title iOS automatic source maps upload [iOS, Xcode] Automatic source map upload is not working in RN 0.75.x Oct 2, 2024
@christianbach
Copy link

@krystofwoldrich great!

0.75.4 is now released https://github.com/facebook/react-native/releases/tag/v0.75.4

@ridvanaltun
Copy link

@krystofwoldrich great!

0.75.4 is now released https://github.com/facebook/react-native/releases/tag/v0.75.4

Tested, It's working

@skogby
Copy link

skogby commented Oct 3, 2024

Great! I will try it out today as well with latest RN release :)

@krystofwoldrich
Copy link
Member

Thank you everyone, with the https://github.com/facebook/react-native/releases/tag/v0.75.4 out we close this issue.

@LydGol90
Copy link
Author

LydGol90 commented Oct 4, 2024

Hi @krystofwoldrich, yes all good here now on latest RN out of the box. Thanks so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Archived in project
Development

No branches or pull requests

5 participants