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

android/ios sourcemap uploads not working with RN 0.74 #3817

Closed
5 tasks
jpaas opened this issue May 14, 2024 · 6 comments
Closed
5 tasks

android/ios sourcemap uploads not working with RN 0.74 #3817

jpaas opened this issue May 14, 2024 · 6 comments

Comments

@jpaas
Copy link

jpaas commented May 14, 2024

OS:

  • Windows
  • [ x] MacOS
  • Linux

Platform:

  • [x ] iOS
  • [x ] Android

SDK:

  • [x ] @sentry/react-native (>= 1.0.0)
  • react-native-sentry (<= 0.43.2)

SDK version: 5.2.22

react-native version: 0.74.1

Are you using Expo?

  • Yes
  • [x ] No

Are you using sentry.io or on-premise?

  • [ x] sentry.io (SaaS)
  • on-premise

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

N/A

Configuration:

N/A


I have the following issue:

When I try to build an android or ios release build, the sentry integration attempts to upload the source maps, but has difficulty finding them.

Steps to reproduce:

  • Configure with automatic sourcemap uploading and try to do a release build

Actual result:

android: Sentry is looking for the sourcemap at build/generated/sourcemaps/react/release/index.android.bundle.map when it was generated at build/intermediates/sourcemaps/react/release/index.android.bundle.packager.map

info Writing bundle output to:, /Users/jpaas/Documents/karma/karma-development/apps/worker-native/android/app/build/generated/assets/createBundleReleaseJsAndAssets/index.android.bundle
info Writing sourcemap output to:, /Users/jpaas/Documents/karma/karma-development/apps/worker-native/android/app/build/intermediates/sourcemaps/react/release/index.android.bundle.packager.map
info Done writing bundle output
info Done writing sourcemap output
info Copying 18 asset files
info Done copying assets

> Task :app:createBundleReleaseJsAndAssets FAILED

> Task :app:createBundleReleaseJsAndAssets_SentryUpload_com.karmacasting@3.6.1+272_272 FAILED
Copy `debugId` from packager source map to Hermes source map...
Hermes source map not found. ((A path to copy `debugId` to))
Check generated source map for Debug ID: /Users/jpaas/Documents/karma/karma-development/apps/worker-native/android/app/build/generated/sourcemaps/react/release/index.android.bundle.map does not exist.

Sentry Source Maps upload will include the release name and dist.
Sentry-CLI arguments: [/Users/jpaas/Documents/karma/karma-development/node_modules/@sentry/cli/bin/sentry-cli, --log-level, debug, react-native, gradle, --bundle, /Users/jpaas/Documents/karma/karma-development/apps/worker-native/android/app/build/generated/assets/createBundleReleaseJsAndAssets/index.android.bundle, --sourcemap, /Users/jpaas/Documents/karma/karma-development/apps/worker-native/android/app/build/generated/sourcemaps/react/release/index.android.bundle.map, --release, [email protected]+272, --dist, 272]
  INFO    2024-05-14 14:25:42.057297 -04:00 Loaded file referenced by SENTRY_PROPERTIES (/Users/jpaas/Documents/karma/karma-development/apps/worker-native/android/sentry.properties)
  INFO    2024-05-14 14:25:42.057527 -04:00 Loaded config from /Users/jpaas/.sentryclirc
  DEBUG   2024-05-14 14:25:42.057534 -04:00 sentry-cli version: 2.30.2, platform: "darwin", architecture: "arm64"
  INFO    2024-05-14 14:25:42.057546 -04:00 sentry-cli was invoked with the following command line: "/Users/jpaas/Documents/karma/karma-development/node_modules/@sentry/cli-darwin/bin/sentry-cli" "--log-level" "debug" "react-native" "gradle" "--bundle" "/Users/jpaas/Documents/karma/karma-development/apps/worker-native/android/app/build/generated/assets/createBundleReleaseJsAndAssets/index.android.bundle" "--sourcemap" "/Users/jpaas/Documents/karma/karma-development/apps/worker-native/android/app/build/generated/sourcemaps/react/release/index.android.bundle.map" "--release" "[email protected]+272" "--dist" "272"
  INFO    2024-05-14 14:25:42.057773 -04:00 Issuing a command for Organization: karma-casting Project: worker-native-app
  INFO    2024-05-14 14:25:42.057783 -04:00   bundle path: /Users/jpaas/Documents/karma/karma-development/apps/worker-native/android/app/build/generated/assets/createBundleReleaseJsAndAssets/index.android.bundle
Processing react-native sourcemaps for Sentry upload.
  INFO    2024-05-14 14:25:42.057787 -04:00   sourcemap path: /Users/jpaas/Documents/karma/karma-development/apps/worker-native/android/app/build/generated/sourcemaps/react/release/index.android.bundle.map
error: No such file or directory (os error 2)

ios: Sentry is looking for main.jsbundle.map in the wrong place. It does not exist in Release-iphoneos. It does exist in WorkerNativeApp.app.

info Writing bundle output to:, /Users/jpaas/Library/Developer/Xcode/DerivedData/WorkerNativeApp-ayadnqerqarsenebfzvufzqlcudg/Build/Intermediates.noindex/ArchiveIntermediates/WorkerNativeApp/BuildProductsPath/Release-iphoneos/main.jsbundle
info Writing sourcemap output to:, /Users/jpaas/Library/Developer/Xcode/DerivedData/WorkerNativeApp-ayadnqerqarsenebfzvufzqlcudg/Build/Intermediates.noindex/ArchiveIntermediates/WorkerNativeApp/IntermediateBuildFilesPath/WorkerNativeApp.build/Release-iphoneos/WorkerNativeApp.build/DerivedSources/main.jsbundle.map
...
+ HBC_SOURCEMAP_FILE=/Users/jpaas/Library/Developer/Xcode/DerivedData/WorkerNativeApp-ayadnqerqarsenebfzvufzqlcudg/Build/Intermediates.noindex/ArchiveIntermediates/WorkerNativeApp/BuildProductsPath/Release-iphoneos/WorkerNativeApp.app/main.jsbundle.map
+ /Users/jpaas/Documents/karma/karma-development/node_modules/@sentry/cli-darwin/bin/sentry-cli /Users/jpaas/Documents/karma/karma-development/node_modules/react-native/scripts/compose-source-maps.js /Users/jpaas/Library/Developer/Xcode/DerivedData/WorkerNativeApp-ayadnqerqarsenebfzvufzqlcudg/Build/Intermediates.noindex/ArchiveIntermediates/WorkerNativeApp/BuildProductsPath/Release-iphoneos/main.jsbundle.map /Users/jpaas/Library/Developer/Xcode/DerivedData/WorkerNativeApp-ayadnqerqarsenebfzvufzqlcudg/Build/Intermediates.noindex/ArchiveIntermediates/WorkerNativeApp/BuildProductsPath/Release-iphoneos/WorkerNativeApp.app/main.jsbundle.map -o /Users/jpaas/Library/Developer/Xcode/DerivedData/WorkerNativeApp-ayadnqerqarsenebfzvufzqlcudg/Build/Intermediates.noindex/ArchiveIntermediates/WorkerNativeApp/IntermediateBuildFilesPath/WorkerNativeApp.build/Release-iphoneos/WorkerNativeApp.build/DerivedSources/main.jsbundle.map
node:fs:448
    return binding.readFileUtf8(path, stringToFlags(options.flag));
                   ^

Error: ENOENT: no such file or directory, open '/Users/jpaas/Library/Developer/Xcode/DerivedData/WorkerNativeApp-ayadnqerqarsenebfzvufzqlcudg/Build/Intermediates.noindex/ArchiveIntermediates/WorkerNativeApp/BuildProductsPath/Release-iphoneos/main.jsbundle.map'
    at Object.readFileSync (node:fs:448:20)
    at Object.<anonymous> (/Users/jpaas/Documents/karma/karma-development/node_modules/react-native/scripts/compose-source-maps.js:34:8)
    at Module._compile (node:internal/modules/cjs/loader:1358:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
    at Module.load (node:internal/modules/cjs/loader:1208:32)
    at Module._load (node:internal/modules/cjs/loader:1024:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:174:12)
    at node:internal/main/run_main_module:28:49 {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/Users/jpaas/Library/Developer/Xcode/DerivedData/WorkerNativeApp-ayadnqerqarsenebfzvufzqlcudg/Build/Intermediates.noindex/ArchiveIntermediates/WorkerNativeApp/BuildProductsPath/Release-iphoneos/main.jsbundle.map'
}

Expected result:

It finds the sourcemaps and uploads them.

@krystofwoldrich
Copy link
Member

krystofwoldrich commented May 15, 2024

Hi @jpaas,
thank you for the message,
from the log I can see that you are using Hermes.

On Android the build/intermediates/sourcemaps/react/release/index.android.bundle.packager.map path leads to the Metro Packager source map which is not the final composed Hermes source map. Do you know where was the composed source map generated in your application?

On iOS the /Users/jpaas/Library/Developer/Xcode/DerivedData/WorkerNativeApp-ayadnqerqarsenebfzvufzqlcudg/Build/Intermediates.noindex/ArchiveIntermediates/WorkerNativeApp/BuildProductsPath/Release-iphoneos/WorkerNativeApp.app/main.jsbundle.map is path to Hermes source map before composition with the packager. The pure Hermes source map won't work, the composed source map is needed.

For Android do you change any React Native settings in app/build.gradle, for example Hermes Compiler flags?

For iOS could you share with us your Bundle React Native code and images build phase, specifically do you set EXTRA_PACKAGER_FLAGS, or SOURCEMAP_FILE?

Have the source map upload work for you before upgrade to the latest RN version?

@jpaas
Copy link
Author

jpaas commented May 15, 2024

Hi @krystofwoldrich
Yes the sourcemap uploads worked before the upgrade. I upgraded from RN 0.72 to 0.74 using the RN upgrade tool (https://react-native-community.github.io/upgrade-helper/).

It basically just has me upgrading the targets and tool versions, adding the kotlin-gradle-plugin, removing flipper.

On iOS I think my Bundle React Native code and images had gotten a bit stale. I was doing this...
EXTRA_PACKAGER_ARGS="--sourcemap-output $DERIVED_FILE_DIR/main.jsbundle.map"

I changed it to this and it now works. BTW I think the sentry docs at https://docs.sentry.io/platforms/react-native/manual-setup/manual-setup/#using-node-with-nvm-or-volta are wrong because if I don't define SOURCEMAP_FILE, metro will not generate a source map at all. Also FWIW, even though I use the standard sentry.properties file in the ios dir, if I don't define export SENTRY_PROPERTIES=sentry.properties, native crashes will not be reported.

if [ "${CONFIGURATION}" == "Release" ]; then
  export SOURCEMAP_FILE=$DERIVED_FILE_DIR/main.jsbundle.map
fi

On android is there some step I'm missing to compose the source maps? The bundling and uploading of sourcemaps all happens inside the gradle bundleRelease task, so I'm not sure how to insert it. I assumed the sentry plugin would handle it. I was just trying to follow the sentry docs at https://docs.sentry.io/platforms/react-native/manual-setup/manual-setup

One thing I did just discover is new that I was missing is the custom metro serializer, so I added that, but it didn't change anything.

@krystofwoldrich
Copy link
Member

Hi @jpaas,
I'm happy to hear that iOS is working. If you use sentry-xcode.sh (https://docs.sentry.io/platforms/react-native/manual-setup/manual-setup/#configure-automatic-source-maps-upload) the SOURCEMAP_FILE and SENTRY_PROPERTIES are automatically set.

For Android, the compose source maps are handled by RN, https://github.com/facebook/react-native/blob/31f9d45074f069151c155836335e0edff87f70bd/packages/react-native-gradle-plugin/src/main/kotlin/com/facebook/react/tasks/BundleHermesCTask.kt#L102

Do you change any React Native settings in app/build.gradle, for example Hermes Compiler flags?

You can check if the Hermes compiler source map is generated the path should be /Users/jpaas/Documents/karma/karma-development/apps/worker-native/android/app/build/intermediates/sourcemaps/react/release/index.android.bundle.compiler.map

index.android.bundle.compiler.map and index.android.bundle.packager.map are used to create the final source map.

@jpaas
Copy link
Author

jpaas commented May 17, 2024

re: Android

I'm not setting any hermes compile flags. I don't see a index.android.bundle.compiler.map. Here's a more complete log excerpt. Is it failing to create the compiler sourcemap because of the missing debugID issue?

> Task :app:createBundleReleaseJsAndAssets
debug Reading Metro config from /Users/jpaas/Documents/karma/karma-development/apps/worker-native/metro.config.js
warning: the transform cache was reset.
                Welcome to Metro v0.80.9
              Fast - Scalable - Integrated
info Writing bundle output to:, /Users/jpaas/Documents/karma/karma-development/apps/worker-native/android/app/build/generated/assets/createBundleReleaseJsAndAssets/index.android.bundle
info Writing sourcemap output to:, /Users/jpaas/Documents/karma/karma-development/apps/worker-native/android/app/build/intermediates/sourcemaps/react/release/index.android.bundle.packager.map
info Done writing bundle output
info Done writing sourcemap output
info Copying 18 asset files
info Done copying assets

> Task :app:createBundleReleaseJsAndAssets FAILED

> Task :app:createBundleReleaseJsAndAssets_SentryUpload_com.karmacasting@3.6.1+272_272 FAILED
Copy `debugId` from packager source map to Hermes source map...
Hermes source map not found. ((A path to copy `debugId` to))
Check generated source map for Debug ID: /Users/jpaas/Documents/karma/karma-development/apps/worker-native/android/app/build/generated/sourcemaps/react/release/index.android.bundle.map does not exist.

Sentry Source Maps upload will include the release name and dist.
Sentry-CLI arguments: [/Users/jpaas/Documents/karma/karma-development/node_modules/@sentry/cli/bin/sentry-cli, --log-level, debug, react-native, gradle, --bundle, /Users/jpaas/Documents/karma/karma-development/apps/worker-native/android/app/build/generated/assets/createBundleReleaseJsAndAssets/index.android.bundle, --sourcemap, /Users/jpaas/Documents/karma/karma-development/apps/worker-native/android/app/build/generated/sourcemaps/react/release/index.android.bundle.map, --release, [email protected]+272, --dist, 272]
  INFO    2024-05-17 12:49:51.453122 -04:00 Loaded file referenced by SENTRY_PROPERTIES (/Users/jpaas/Documents/karma/karma-development/apps/worker-native/android/sentry.properties)
  INFO    2024-05-17 12:49:51.453299 -04:00 Loaded config from /Users/jpaas/.sentryclirc
  DEBUG   2024-05-17 12:49:51.453302 -04:00 sentry-cli version: 2.30.2, platform: "darwin", architecture: "arm64"
  INFO    2024-05-17 12:49:51.453468 -04:00 sentry-cli was invoked with the following command line: "/Users/jpaas/Documents/karma/karma-development/node_modules/@sentry/cli-darwin/bin/sentry-cli" "--log-level" "debug" "react-native" "gradle" "--bundle" "/Users/jpaas/Documents/karma/karma-development/apps/worker-native/android/app/build/generated/assets/createBundleReleaseJsAndAssets/index.android.bundle" "--sourcemap" "/Users/jpaas/Documents/karma/karma-development/apps/worker-native/android/app/build/generated/sourcemaps/react/release/index.android.bundle.map" "--release" "[email protected]+272" "--dist" "272"
Processing react-native sourcemaps for Sentry upload.
  INFO    2024-05-17 12:49:51.454513 -04:00 Issuing a command for Organization: karma-casting Project: worker-native-app
  INFO    2024-05-17 12:49:51.454523 -04:00   bundle path: /Users/jpaas/Documents/karma/karma-development/apps/worker-native/android/app/build/generated/assets/createBundleReleaseJsAndAssets/index.android.bundle
  INFO    2024-05-17 12:49:51.454526 -04:00   sourcemap path: /Users/jpaas/Documents/karma/karma-development/apps/worker-native/android/app/build/generated/sourcemaps/react/release/index.android.bundle.map
error: No such file or directory (os error 2)
  DEBUG   2024-05-17 12:49:51.478943 -04:00 skipping update nagger because session is not attended

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:createBundleReleaseJsAndAssets'.
> A problem occurred starting process 'command '../../../../node_modules/react-native/sdks/hermesc/osx-bin/hermesc''

@jpaas
Copy link
Author

jpaas commented May 17, 2024

re: Android

I'm not setting any hermes compile flags. I don't see a index.android.bundle.compiler.map. Here's a more complete log excerpt. Is it failing to create the compiler sourcemap because of the missing debugID issue?

> Task :app:createBundleReleaseJsAndAssets
debug Reading Metro config from /Users/jpaas/Documents/karma/karma-development/apps/worker-native/metro.config.js
warning: the transform cache was reset.
                Welcome to Metro v0.80.9
              Fast - Scalable - Integrated
info Writing bundle output to:, /Users/jpaas/Documents/karma/karma-development/apps/worker-native/android/app/build/generated/assets/createBundleReleaseJsAndAssets/index.android.bundle
info Writing sourcemap output to:, /Users/jpaas/Documents/karma/karma-development/apps/worker-native/android/app/build/intermediates/sourcemaps/react/release/index.android.bundle.packager.map
info Done writing bundle output
info Done writing sourcemap output
info Copying 18 asset files
info Done copying assets

> Task :app:createBundleReleaseJsAndAssets FAILED

> Task :app:createBundleReleaseJsAndAssets_SentryUpload_com.karmacasting@3.6.1+272_272 FAILED
Copy `debugId` from packager source map to Hermes source map...
Hermes source map not found. ((A path to copy `debugId` to))
Check generated source map for Debug ID: /Users/jpaas/Documents/karma/karma-development/apps/worker-native/android/app/build/generated/sourcemaps/react/release/index.android.bundle.map does not exist.

Sentry Source Maps upload will include the release name and dist.
Sentry-CLI arguments: [/Users/jpaas/Documents/karma/karma-development/node_modules/@sentry/cli/bin/sentry-cli, --log-level, debug, react-native, gradle, --bundle, /Users/jpaas/Documents/karma/karma-development/apps/worker-native/android/app/build/generated/assets/createBundleReleaseJsAndAssets/index.android.bundle, --sourcemap, /Users/jpaas/Documents/karma/karma-development/apps/worker-native/android/app/build/generated/sourcemaps/react/release/index.android.bundle.map, --release, [email protected]+272, --dist, 272]
  INFO    2024-05-17 12:49:51.453122 -04:00 Loaded file referenced by SENTRY_PROPERTIES (/Users/jpaas/Documents/karma/karma-development/apps/worker-native/android/sentry.properties)
  INFO    2024-05-17 12:49:51.453299 -04:00 Loaded config from /Users/jpaas/.sentryclirc
  DEBUG   2024-05-17 12:49:51.453302 -04:00 sentry-cli version: 2.30.2, platform: "darwin", architecture: "arm64"
  INFO    2024-05-17 12:49:51.453468 -04:00 sentry-cli was invoked with the following command line: "/Users/jpaas/Documents/karma/karma-development/node_modules/@sentry/cli-darwin/bin/sentry-cli" "--log-level" "debug" "react-native" "gradle" "--bundle" "/Users/jpaas/Documents/karma/karma-development/apps/worker-native/android/app/build/generated/assets/createBundleReleaseJsAndAssets/index.android.bundle" "--sourcemap" "/Users/jpaas/Documents/karma/karma-development/apps/worker-native/android/app/build/generated/sourcemaps/react/release/index.android.bundle.map" "--release" "[email protected]+272" "--dist" "272"
Processing react-native sourcemaps for Sentry upload.
  INFO    2024-05-17 12:49:51.454513 -04:00 Issuing a command for Organization: karma-casting Project: worker-native-app
  INFO    2024-05-17 12:49:51.454523 -04:00   bundle path: /Users/jpaas/Documents/karma/karma-development/apps/worker-native/android/app/build/generated/assets/createBundleReleaseJsAndAssets/index.android.bundle
  INFO    2024-05-17 12:49:51.454526 -04:00   sourcemap path: /Users/jpaas/Documents/karma/karma-development/apps/worker-native/android/app/build/generated/sourcemaps/react/release/index.android.bundle.map
error: No such file or directory (os error 2)
  DEBUG   2024-05-17 12:49:51.478943 -04:00 skipping update nagger because session is not attended

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:createBundleReleaseJsAndAssets'.
> A problem occurred starting process 'command '../../../../node_modules/react-native/sdks/hermesc/osx-bin/hermesc''

Although I just noticed in my iOS logs it has the same complaint about the debugID, but it continues to upload the sourcemap.

@jpaas
Copy link
Author

jpaas commented May 18, 2024

Arg. The perils of a monorepo setup. So it turns out that every other react native command who's location can be configured - e.g. reactNativeDir, codegenDir, cliFile, are all relative to the android/app dir. But not hermesCommand. It is run from the root of the react native project.

Before I configured it it told me that it couldn't find the command. Once I configured it relative to the wrong dir I got a different error execution failed. So I figured it was running but failing for some reason. Anyhow now that I have it correct, the sourcemap is composed and sentry is able to pick it up.

Sorry for the bother.

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

No branches or pull requests

2 participants