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

sentry-cli fails in yarn monorepo setup #1857

Closed
lew opened this issue Oct 27, 2021 · 16 comments
Closed

sentry-cli fails in yarn monorepo setup #1857

lew opened this issue Oct 27, 2021 · 16 comments
Labels
Expo Issues related to Sentry React Native Expo support monorepo Type: 🪲 Bug

Comments

@lew
Copy link

lew commented Oct 27, 2021

We have an expo app inside a yarn monorepo workspace and our build fails with:

> Task :app:bundleReleaseJsAndAssets
info Writing bundle output to:, /build/workingdir/build/apps/sh.hae.app/android/app/build/generated/assets/react/release/index.android.bundle
info Writing sourcemap output to:, /build/workingdir/build/apps/sh.hae.app/android/app/build/generated/sourcemaps/react/release/index.android.bundle.map
info Done writing bundle output
info Done writing sourcemap output
info Copying 47 asset files
info Done copying assets
> Task :app:bundleReleaseJsAndAssets_SentryUpload_1 FAILED
> Task :app:bundleReleaseJsAndAssets_SentryUploadCleanUp SKIPPED
w: Detected multiple Kotlin daemon sessions at build/kotlin/sessions
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.9/userguide/command_line_interface.html#sec:command_line_warnings
631 actionable tasks: 631 executed
[stderr] FAILURE: Build failed with an exception.
[stderr] * What went wrong:
[stderr] Execution failed for task ':app:bundleReleaseJsAndAssets_SentryUpload_1'.
[stderr] > A problem occurred starting process 'command '/build/workingdir/build/apps/sh.hae.app/node_modules/@sentry/cli/bin/sentry-cli''
[stderr] * Try:
[stderr] Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
[stderr] * Get more help at https://help.gradle.org
[stderr] BUILD FAILED in 6m 57s

The call to /build/workingdir/build/apps/sh.hae.app/node_modules/@sentry/cli/bin/sentry-cli fails because yarn installs @sentry/cli in the workspace root i.e. /build/workingdir/build/node_modules not inside the apps/sh.hae.app subdirectory.

This should be the culprit line:

def cliExecutable = sentryProps.get("cli.executable", "$reactRoot/node_modules/@sentry/cli/bin/sentry-cli")

Expo uses require.resolve within gradle to find package locations in yarn monorepos. e.g. new File(["node", "--print", "require.resolve('@react-native-community/cli-platform-android/package.json')"].execute().text.trim(), "../native_modules.gradle"); maybe this is a possible solution

(first reported to expo/sentry-expo#217)

@byCedric
Copy link

byCedric commented Oct 30, 2021

Hi! My name is Cedric and I work for Expo, just want to pitch in and find some options to resolve this. With Expo SDK 43, one of the new focuses is adding support for monorepositories. I noticed the hardcoded path in the Gradle script as well. We can resolve this in sentry-expo by calculating the cli.executable path, and if it's different compared to this "hardcoded path", we could add the relative location of the Sentry CLI.

Is it safe to add that cli.executable path? As in, will this be supported for future versions? The documentation around this is fairly limited, so just want to check before we add this on our end 😄

@marandaneto
Copy link
Contributor

indeed, cli.executable isn't documented, let me double-check if this is of internal usage only or it'd be fine to patch it.

@marandaneto
Copy link
Contributor

@HazAT is gonna follow up on this.

@Braden1996
Copy link

Little note on this. On Expo's EAS Build, the following script in eas-build-post-install didn't solve the issue:

const path = require("path")
const fs = require("fs")

function main() {
    const sentryCliPath = path.resolve(require.resolve("@sentry/cli/package.json"), "../bin/sentry-cli")

    const iosSentryPropertiesPath = path.resolve(__dirname, "../ios/sentry.properties")
    const androidSentryPropertiesPath = path.resolve(__dirname, "../android/sentry.properties")

    for (const sentryPropertiesPath of [iosSentryPropertiesPath, androidSentryPropertiesPath]) {
        // Not a Sentry build, just ignore.
        if (!fs.existsSync(sentryPropertiesPath)) return

        const sentryProperties = fs.readFileSync(sentryPropertiesPath, "utf8")

        // Already patched.
        if (sentryProperties.includes("cli.executable")) return

        const sentryPropertiesWithSentryCli = `${sentryProperties}\ncli.executable=${sentryCliPath}`

        fs.writeFileSync(sentryPropertiesPath, sentryPropertiesWithSentryCli)
    }
}

main()

We ended up having to set our React Native app to no-hoist, which isn't ideal but unblocks us for now.

@byCedric
Copy link

byCedric commented Nov 9, 2021

We have some code ready to auto-fill the cli.executable in sentry.properties with sentry-expo. I would want to add that as a possible way forward as well! (see code here)

@Braden1996
Copy link

We have some code ready to auto-fill the cli.executable in sentry.properties with sentry-expo. I would want to add that as a possible way forward as well! (see code here)

Hey @byCedric, I tried your fix on my monorepo and unfortunately getting the same issues as both before and with my attempt at a fix (which I believe does the same thing). You can see the build for this here, assuming you have privileges: https://expo.dev/accounts/attio/projects/mobile-app/builds/77ad6652-de8d-477c-9a42-0617b321d878

Here is the bulk of the error on iOS:

› Compiling Attio » main.m
› Compiling Attio » attio_vers.c
› Compiling Attio » AppDelegate.m
› Linking   Attio » attio
› Copying   ios/Attio/Supporting/Expo.plist ➜ ./Expo.plist
› Compiling Attio » SplashScreen.storyboard
› Preparing Attio » Info.plist
› Generating debug Attio » attio.app.dSYM
› Executing Attio » Bundle React Native code and images

❌  error: No such file or directory (os error 2)

    the transform cache was reset.

[[ REDACTED BUNDLE NOISE ]]

› Executing Attio » [CP] Copy Pods Resources
› Executing Attio » Upload Debug Symbols to Sentry
› Executing Attio » [CP] Embed Pods Frameworks
› Signing   Attio » attio.app
› Creating  Attio » attio.app
▸ ** ARCHIVE FAILED **
** ARCHIVE FAILED **
Exit status: 65
+-------------+-------------------------+
|           Build environment           |
+-------------+-------------------------+
| xcode_path  | /Applications/Xcode.app |
| gym_version | 2.185.1                 |
| sdk         | iPhoneOS15.0.sdk        |
+-------------+-------------------------+
Looks like fastlane ran into a build/archive error with your project
It's hard to tell what's causing the error, so we wrote some guides on how
to troubleshoot build and signing issues: https://docs.fastlane.tools/codesigning/getting-started/
Before submitting an issue on GitHub, please follow the guide above and make
sure your project is set up correctly.
fastlane uses `xcodebuild` commands to generate your binary, you can see the
the full commands printed out in yellow in the above log.
Make sure to inspect the output above, as usually you'll find more error information there
[stderr] [!] Error building the application - see the log above
Error: Fastlane build failed with unknown error. Please refer to the "Run fastlane" and "Xcode Logs" phases.
Fastlane errors in most cases are not printed at the end of the output, so you may not find any useful information in the last lines of output when looking for an error message.

The issue seems to be error: No such file or directory (os error 2) right at the start of the bundle phase. I imagine this is likely related to the Sentry CLI call which wraps the React Native bundle command. I've been unable to pinpoint what's outputting the error.

@Braden1996
Copy link

Braden1996 commented Nov 12, 2021

We have some code ready to auto-fill the cli.executable in sentry.properties with sentry-expo. I would want to add that as a possible way forward as well! (see code here)

Hey @byCedric, I tried your fix on my monorepo and unfortunately getting the same issues as both before and with my attempt at a fix (which I believe does the same thing). You can see the build for this here, assuming you have privileges: https://expo.dev/accounts/attio/projects/mobile-app/builds/77ad6652-de8d-477c-9a42-0617b321d878

Here is the bulk of the error on iOS:

› Compiling Attio » main.m
› Compiling Attio » attio_vers.c
› Compiling Attio » AppDelegate.m
› Linking   Attio » attio
› Copying   ios/Attio/Supporting/Expo.plist ➜ ./Expo.plist
› Compiling Attio » SplashScreen.storyboard
› Preparing Attio » Info.plist
› Generating debug Attio » attio.app.dSYM
› Executing Attio » Bundle React Native code and images

❌  error: No such file or directory (os error 2)

    the transform cache was reset.

[[ REDACTED BUNDLE NOISE ]]

› Executing Attio » [CP] Copy Pods Resources
› Executing Attio » Upload Debug Symbols to Sentry
› Executing Attio » [CP] Embed Pods Frameworks
› Signing   Attio » attio.app
› Creating  Attio » attio.app
▸ ** ARCHIVE FAILED **
** ARCHIVE FAILED **
Exit status: 65
+-------------+-------------------------+
|           Build environment           |
+-------------+-------------------------+
| xcode_path  | /Applications/Xcode.app |
| gym_version | 2.185.1                 |
| sdk         | iPhoneOS15.0.sdk        |
+-------------+-------------------------+
Looks like fastlane ran into a build/archive error with your project
It's hard to tell what's causing the error, so we wrote some guides on how
to troubleshoot build and signing issues: https://docs.fastlane.tools/codesigning/getting-started/
Before submitting an issue on GitHub, please follow the guide above and make
sure your project is set up correctly.
fastlane uses `xcodebuild` commands to generate your binary, you can see the
the full commands printed out in yellow in the above log.
Make sure to inspect the output above, as usually you'll find more error information there
[stderr] [!] Error building the application - see the log above
Error: Fastlane build failed with unknown error. Please refer to the "Run fastlane" and "Xcode Logs" phases.
Fastlane errors in most cases are not printed at the end of the output, so you may not find any useful information in the last lines of output when looking for an error message.

The issue seems to be error: No such file or directory (os error 2) right at the start of the bundle phase. I imagine this is likely related to the Sentry CLI call which wraps the React Native bundle command. I've been unable to pinpoint what's outputting the error.

Managed to get this working by symlinking node_modules/react-native from root into my React Native app's workspace, i.e. "postinstall-symlink-react-native": "ln -sf ../../../node_modules/react-native/ ./node_modules/react-native",

@marandaneto
Copy link
Contributor

if you do the manual configuration https://docs.sentry.io/platforms/react-native/manual-setup/manual-setup/ you could specify the path of the directory either via symlink as @Braden1996 did or really setting up the correct path.

I'm not sure we can do something about it, ideas?

@tyrauber
Copy link

Thanks @byCedric for raising this issue. We've had to fallback to a JS Sentry instrumentation in production. With the sentry-expo config plugin enabled, our app builds locally, but fails on EAS (for both android and ios). It's an Expo 42 expo-yarn-workspaces monorepo architecture, but other config plugins build fine. Our implementation is similar to the one found here.

Is it possible that the EAS build issues we are experiencing are related to this issue?

The build fails at the very end of Fast Lane process:

› Executing TheOutboundStaging » Bundle React Native code and images
    the transform cache was reset.

❌  error: File /Users/expo/Library/Developer/Xcode/DerivedData/.../main.jsbundle does not exist. This must be a bug with the transform cache was reset.

We've tried configuring cli.executable and setting up a postinstall-symlink-react-native symlink, with no success. Any other suggestions on how we might debug and resolve this?

@Braden1996
Copy link

Thanks @byCedric for raising this issue. We've had to fallback to a JS Sentry instrumentation in production. With the sentry-expo config plugin enabled, our app builds locally, but fails on EAS (for both android and ios). It's an Expo 42 expo-yarn-workspaces monorepo architecture, but other config plugins build fine. Our implementation is similar to the one found here.

Is it possible that the EAS build issues we are experiencing are related to this issue?

The build fails at the very end of Fast Lane process:

› Executing TheOutboundStaging » Bundle React Native code and images
    the transform cache was reset.

❌  error: File /Users/expo/Library/Developer/Xcode/DerivedData/.../main.jsbundle does not exist. This must be a bug with the transform cache was reset.

We've tried configuring cli.executable and setting up a postinstall-symlink-react-native symlink, with no success. Any other suggestions on how we might debug and resolve this?

Have you tried SDK 43 by chance? There was a lot of added monorepo support in that release. We're currently running a monorepo w/ sentry-expo and it seems to be working now (with the react-native symlink described above).

@marandaneto
Copy link
Contributor

marandaneto commented Nov 23, 2021

indeed, cli.executable isn't documented, let me double-check if this is of internal usage only or it'd be fine to patch it.

@byCedric cli.executable is a public config and can be used, although this would only work for Android, since the Gradle bits look for it before calling sentry-cli

See: https://github.com/getsentry/sentry-react-native/blob/master/sentry.gradle#L95

Although for iOS, unfortunately, this is not true, the CLI path has to be changed in the sentry build phase script, usually under the project.pbxproj, this is patched by sentry-wizard during install steps, See https://github.com/getsentry/sentry-wizard/blob/master/lib/Steps/Integrations/ReactNative.ts#L248

Build phases:
Bundle React Native Code And Images and Upload Debug Symbols to Sentry

or just search for @sentry/cli/bin/sentry-cli and fix the path accordingly.

@marandaneto
Copy link
Contributor

I've raised this issue #1912
so iOS eventually respects the cli.executable config too instead of always hardcoded.

@tyrauber
Copy link

Hi @Braden1996, Expo 43 migration is in progress. Ran into a bunch of little issues like this, but overall quite happy with the changes. In regards to sentry, I was able to get Native Reporting to work by adding the "postinstall-symlink-react-native", .../.../../ for ./apps/app/.... One thing to note though, I actually had to disable the sentry postPublish hook as it would mysteriously err out toward the end of the fast lane build:

› Executing TheOutboundStaging » Bundle React Native code and images

❌  error: No such file or directory (os error 2)

    the transform cache was reset.
› Generating debug

That took way longer than I'd like to admit to figure out. Not sure if this is related to my application environment, or overwriting the react-native symlink, but disabling the hook enabled the builds to pass on EAS.

@marandaneto
Copy link
Contributor

Android should be able to detect the correct folder automatically after #1917
closing this issue in favor of #1912

@ovidiuch
Copy link

ovidiuch commented Mar 1, 2022

We ended up having to set our React Native app to no-hoist, which isn't ideal but unblocks us for now.

@Braden1996 Can you share your nohoist config? Did you set nohoist for the entire monorepo or just for specific Sentry packages? Thanks.

@czystyl
Copy link

czystyl commented Sep 12, 2022

If you still have some issues, you can try this: byCedric/expo-monorepo-example#32 (comment)

@kahest kahest added the Expo Issues related to Sentry React Native Expo support label Jan 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Expo Issues related to Sentry React Native Expo support monorepo Type: 🪲 Bug
Projects
None yet
Development

No branches or pull requests

8 participants