getsentry / sentry-react-native

Official Sentry SDK for React Native
https://sentry.io
MIT License
1.56k stars 330 forks source link

IOS build: Sentry fails with RN 0.75 #4036

Closed theJovian closed 2 weeks ago

theJovian commented 3 weeks ago

OS:

Platform:

SDK:

SDK version: 5.30.0

react-native version: 0.75.1

Are you using Expo?

Are you using sentry.io or on-premise?

If you are using sentry.io, please post a link to your issue so we can take a look: N/A

Configuration:

(@sentry/react-native)

Sentry.init({
  dsn: 'https://b62248221f8eb3d25d64fbea47abcfce@o4507570411208704.ingest.de.sentry.io/4507808288407632',
});

I have the following issue:

The following error appears when building for ios in release

Image

Steps to reproduce:

Actual result:

Build fails

Expected result:

Build succeeds

sbeigel commented 3 weeks ago

Same. I checked it and the Sentry CLI seems to overwrite the $NODE_BINARY env variable. I added a echo $NODE_BINARY in react-native-xcode.sh and the output shows the sentry cli, not /path/to/node

A workaround for now (at least for me) is, to patch react-native-xcode.sh and replace the env var with the (locally correct) hard-coded node path (i.e. just "node" or "/usr/local/bin/node" or whatever).

krystofwoldrich commented 3 weeks ago

Hi @theJovian and @sbeigel,

thank you for the report, the React Native new xcode script is currently not compatible with the sentry stript out of the box. We will fix this soon.

You can use the following workaround, manually set the new React Native config command.

export CONFIG_CMD="$NODE_BINARY $NODE_ARGS $REACT_NATIVE_PATH/cli.js config"
export CONFIG_APP="${CONFIG_CMD}"
krystofwoldrich commented 3 weeks ago

We will need to investigate why https://github.com/getsentry/sentry-cli/blob/a2a4d543f4d191db553f7b1b3385c5cd0c9cfefd/src/commands/react_native/xcode.rs#L425 doesn't execute the https://github.com/getsentry/sentry-cli/blob/a2a4d543f4d191db553f7b1b3385c5cd0c9cfefd/src/commands/react_native/xcode.rs#L425 correctly.

xuanmai-agilityio commented 2 weeks ago

I see one more issue with Bundle React Native code and images patch script. It will not bundle the main.jsbundle and assets to the ipa file when archiving, making the app crash on start. Btw, I'm using Sentry with Nx monorepo.

krystofwoldrich commented 2 weeks ago

@xuanmai-agilityio Has this change with upgrade to 0.75? And the workaround from https://github.com/getsentry/sentry-react-native/issues/4036#issuecomment-2298451212 doesn't work?

jieey1140 commented 2 weeks ago

same issue

xuanmai-agilityio commented 2 weeks ago

@krystofwoldrich Do you mean to update the Bundle React Native code and images like this? Just tried but it didn't work.

Image

theJovian commented 2 weeks ago

Based on this comment: https://github.com/getsentry/sentry-react-native/issues/4036#issuecomment-2298451212

We got something like this and is working for us:

Image

Maybe we are missing $NODE_ARGS though

krystofwoldrich commented 2 weeks ago

@xuanmai-agilityio @theJovian Yes, both looks good.

The missing $NODE_ARGS are okay, unless you are using them yourself, by default they are empty.

krystofwoldrich commented 2 weeks ago

I've update the code snippet.

This is now easy copy paste.

export CONFIG_CMD="$NODE_BINARY $NODE_ARGS $REACT_NATIVE_PATH/cli.js config"
export CONFIG_APP="${CONFIG_CMD}"

The snippet will work with the future fix in the RN script.

As well as the Sentry CLI fix.

xuanmai-agilityio commented 2 weeks ago

It didn't work on my end with the fix below. Furthermore, I'm also using the Nx mono repo. Are there any differences in configuring on a mono repo?

Image

krystofwoldrich commented 2 weeks ago

@xuanmai-agilityio Do you get any errors?

alexborton commented 2 weeks ago

Would you anticipate this working within a CircleCI environment during build?

kahest commented 2 weeks ago

Report of this still happening with 5.31.0 (with new arch enabled): https://github.com/getsentry/sentry-react-native/issues/4052

lovegaoshi commented 2 weeks ago

the same error in the linked issue above persists with RN 0.75.2, sentry 5.31.0 with the old architecture built with github actions. safe to say sentry is still not compatible with RN 0.75 right now

2024-08-27T19:12:31.0110520Z + EXTRA_ARGS+=("--config-cmd" "$NODE_BINARY $NODE_ARGS $REACT_NATIVE_DIR/cli.js config")
2024-08-27T19:12:31.0116630Z + /Users/runner/work/azusa-player-mobile/azusa-player-mobile/node_modules/@sentry/cli-darwin/bin/sentry-cli /Users/runner/work/azusa-player-mobile/azusa-player-mobile/node_modules/react-native/scripts/bundle.js --config-cmd '' --entry-file index.js --platform ios --dev false --reset-cache --bundle-output /Users/runner/Library/Developer/Xcode/DerivedData/example-dogmvunyynjjkkhewueaqvycrhvv/Build/Intermediates.noindex/ArchiveIntermediates/APM/BuildProductsPath/Release-iphoneos/main.jsbundle --assets-dest /Users/runner/Library/Developer/Xcode/DerivedData/example-dogmvunyynjjkkhewueaqvycrhvv/Build/Intermediates.noindex/ArchiveIntermediates/APM/BuildProductsPath/Release-iphoneos/AzusaPlayer.app --sourcemap-output /Users/runner/Library/Developer/Xcode/DerivedData/example-dogmvunyynjjkkhewueaqvycrhvv/Build/Intermediates.noindex/ArchiveIntermediates/APM/BuildProductsPath/Release-iphoneos/main.jsbundle.map --minify false --config-cmd '/Users/runner/work/azusa-player-mobile/azusa-player-mobile/node_modules/@sentry/cli-darwin/bin/sentry-cli  /Users/runner/work/azusa-player-mobile/azusa-player-mobile/node_modules/react-native/cli.js config'
2024-08-27T19:12:31.0122770Z error: unrecognized subcommand '/Users/runner/work/azusa-player-mobile/azusa-player-mobile/node_modules/react-native/cli.js'
2024-08-27T19:12:31.0123330Z 
2024-08-27T19:12:31.0123500Z Usage: sentry-cli [OPTIONS] <COMMAND>
2024-08-27T19:12:31.0123730Z 
2024-08-27T19:12:31.0123900Z For more information, try '--help'.
2024-08-27T19:12:31.0124430Z node:internal/errors:984
2024-08-27T19:12:31.0124740Z   const err = new Error(message);
2024-08-27T19:12:31.0125030Z               ^
2024-08-27T19:12:31.0125170Z 
2024-08-27T19:12:31.0126290Z Error: Command failed: /Users/runner/work/azusa-player-mobile/azusa-player-mobile/node_modules/@sentry/cli-darwin/bin/sentry-cli  /Users/runner/work/azusa-player-mobile/azusa-player-mobile/node_modules/react-native/cli.js config
2024-08-27T19:12:31.0127840Z error: unrecognized subcommand '/Users/runner/work/azusa-player-mobile/azusa-player-mobile/node_modules/react-native/cli.js'

https://productionresultssa3.blob.core.windows.net/actions-results/9e21290a-4def-4020-8129-fc95fb60a04e/workflow-job-run-eae0f608-ea3b-5872-5780-858ef628eb1e/logs/job/job-logs.txt?rsct=text%2Fplain&se=2024-08-27T19%3A24%3A45Z&sig=LibEVq%2FyW8MQcZCEcXe9V%2FzVqY7v%2B%2BKf9Irllgh6SFU%3D&ske=2024-08-28T03%3A26%3A58Z&skoid=ca7593d4-ee42-46cd-af88-8b886a2f84eb&sks=b&skt=2024-08-27T15%3A26%3A58Z&sktid=398a6654-997b-47e9-b12b-9515b896b4de&skv=2024-05-04&sp=r&spr=https&sr=b&st=2024-08-27T19%3A14%3A40Z&sv=2024-05-04

abdoerrahiem commented 2 weeks ago

got the same issue

xuanmai-agilityio commented 2 weeks ago

Got this issue when running with updated Bundle React Native code and images scripts.

Error: Command failed: /Users/maixuan/Develop/AsNet/AgilityKash/apps/consumer-mobile/ios/Pods/../../node_modules/react-native/cli.js config
env: node: No such file or directory

    at checkExecSyncError (node:child_process:890:11)
sbeigel commented 2 weeks ago

I'm not a sentry developer, but to me it looks like this issue is fixed by #2131 but this fix is NOT released yet and NEITHER included in @sentry/react-native. So we have to wait for that (and use custom patches until it's released).

kahest commented 2 weeks ago

@sbeigel that's correct, the fix needs to be released with sentry-cli and then bumped in @sentry/react-native. We'll update this issue when it becomes available.

krystofwoldrich commented 2 weeks ago

@xuanmai-agilityio For monorepos you will need to adjust the path to the react-native package.

Based on the error you got, something like this should work.

export CONFIG_CMD="$NODE_BINARY $NODE_ARGS ../../../../node_modules/react-native/cli.js config"
export CONFIG_APP="${CONFIG_CMD}"
krystofwoldrich commented 2 weeks ago

Fix released in 5.31.1

Asad520 commented 2 weeks ago

I am getting still facing an error on 5.31.1.

No bundle URL present.

Make sure you're running a packager server or have included a .jsbundle file in your application bundle.
*** Terminating app due to uncaught exception 'RCTFatalException: No bundle URL present.

Make sure you're running a packager server or have included a .jsbundle file in your application bundle.', reason: 'No bundle URL present.

These are my project versions (I'm not using expo):

"@sentry/react-native": "^5.31.1",
    "react": "18.3.1",
    "react-native": "0.75.1"

These are the content from Bundle React Native code and Images (auto-generated):

set -e

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\"\""

and these are in Upload Debug Symbols to Sentry (also auto-generated):

/bin/sh ../node_modules/@sentry/react-native/scripts/sentry-xcode-debug-files.sh

The issue doesn't exist if I remove Sentry. Is this related to the parent issue? or any work arounds?

jieey1140 commented 1 week ago

@Asad520

It seems to work with pnpm monorepo + React Native 0.75.2 + sentry 5.31.1.

Not finding the above jsbundle seems to be a different issue!

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"

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

How about trying the above?

Asad520 commented 1 week ago

@jieey1140 The script you provided worked for me. Thank you! 🥳

chrisfinch commented 4 days ago

Still getting this issue:

"react-native": "^0.75.2",
"@sentry/react-native": "^5.31.1",
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"

/bin/sh -c "$WITH_ENVIRONMENT \"/bin/sh ../node_modules/@sentry/react-native/scripts/sentry-xcode.sh $REACT_NATIVE_XCODE\""
▸ Running script 'Bundle React Native code and images'

❌  error: sentry-cli - To disable source maps auto upload, set SENTRY_DISABLE_AUTO_UPLOAD=true in your environment variables. Or to allow failing upload, set SENTRY_ALLOW_FAILURE=true

❌  error: sentry-cli -   INFO    2024-09-07 22:48:57.253587 -07:00 Loaded file referenced by SENTRY_PROPERTIES (sentry.properties)

❌  error: unrecognized subcommand '/Users/christopherfinch/Projects/KeyhiveIoPhoneApp/node_modules/react-native/cli.js'

❌  error: unrecognized subcommand '/Users/christopherfinch/Projects/KeyhiveIoPhoneApp/node_modules/react-native/cli.js'

I've now wasted many hours trying to debug. My next step is removing sentry altogether.

Please advise.

cc @krystofwoldrich

krystofwoldrich commented 3 days ago

Hi @chrisfinch,

I'm sorry to hear that.

If you are running in the auto upload issue, you can always use SENTRY_DISABLE_AUTO_UPLOAD=true, to build the application without the auto source maps upload and then run the comman manually https://docs.sentry.io/platforms/react-native/sourcemaps/


Based on the output, the sentry-xcode.sh is still using the old version of sentry-cli.

The script uses the Node JS resolution to get the binary require.resolve('@sentry/cli/package.json') possibly you have multiple version of the Sentry CLI installed.

You can try to run node --print "require('path').dirname(require.resolve('@sentry/cli/package.json'))" in the RN project root to check the path resolves. You can also use SENTRY_CLI_EXECUTABLE env to manually select the path or install the sentry-cli@latest JS package manually.