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 #217

Closed
lew opened this issue Oct 14, 2021 · 14 comments
Closed

sentry-cli fails in yarn monorepo setup #217

lew opened this issue Oct 14, 2021 · 14 comments
Labels

Comments

@lew
Copy link

lew commented Oct 14, 2021

Summary

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

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");

Managed or bare workflow? If you have ios/ or android/ directories in your project, the answer is bare!

bare

What platform(s) does this occur on?

Android

SDK Version (managed workflow only)

No response

Environment

 Expo CLI 4.12.1 environment info:
    System:
      OS: Linux 5.11 Debian GNU/Linux 10 (buster) 10 (buster)
      Shell: 5.0.3 - /bin/bash
    Binaries:
      Node: 16.0.0 - /usr/local/bin/node
      Yarn: 3.0.2 - /usr/bin/yarn
      npm: 7.21.1 - /usr/local/share/npm-global/bin/npm
    npmGlobalPackages:
      expo-cli: 4.12.1
    Expo Workflow: bare

Reproducible demo or steps to reproduce from a blank project

  1. Create a blank repo with yarn init
  2. Create a new expo project in a subdirectory and add sentry
  3. Link the subdirectory as a workspace in root package.json
"workspaces": [
  "apps/*"
]
  1. yarn install
  2. build the app
@cruzach
Copy link
Contributor

cruzach commented Oct 20, 2021

what version of sentry-expo are you using

@lew
Copy link
Author

lew commented Oct 22, 2021

4.0.3

@cruzach
Copy link
Contributor

cruzach commented Oct 25, 2021

so what's the output when you run node --print "require.resolve('@react-native-community/cli-platform-android/package.json')"

@lew
Copy link
Author

lew commented Oct 27, 2021

Output:
/build/workingdir/build/node_modules/@react-native-community/cli-platform-android/package.json

@cruzach
Copy link
Contributor

cruzach commented Oct 27, 2021

I think this is an upstream sentry problem: app:bundleReleaseJsAndAssets_SentryUpload_1 is part of Sentry's scripts, not sentry-expo's

As you pointed out, sentry-expo's scripts correctly resolve to /build/workingdir/build/node_modules/@react-native-community/cli-platform-android/package.json

What we need is a way to override the cli executable here: https://github.com/getsentry/sentry-react-native/blob/master/sentry.gradle#L95. Since you're in the bare workflow, you can do this now by adding cli.executable=<path> to your sentry.properties file in the android/ folder (not sure why that property is not documented, so use at your own risk)

@lew
Copy link
Author

lew commented Oct 27, 2021

@jamesisaac
Copy link

@cruzach @byCedric It was my understanding that Expo Config Plugins ( https://docs.expo.dev/guides/config-plugins/ ) allow Managed EAS Build projects to use libraries that require native changes.

From what I can see, sentry-expo already has a Config Plugin, just the issue is that it doesn't support a monorepo structure?

It's certainly possible to get Sentry working in a bare RN monorepo - there's just a couple of extra native steps required. So while it would be nice for Sentry to remove the need for those steps (which I think they have on their radar in getsentry/sentry-react-native#1912 ), wouldn't a good solution in the mean time be to update the sentry-expo Config Plugin to check for a monorepo structure, and if so make these extra tweaks? I believe all the error messages people are reporting are the same ones you'd see if you have a bare RN project and hadn't applied the final steps.

It's very unfortunate at the moment that EAS Build + Monorepo + Sentry seem completely incompatible at the moment (no workaround that I'm aware of).

Here are the extra steps that have worked for me in the past (beyond what @sentry/wizard does automatically) to get Sentry working on a Monorepo:

android/sentry.properties

Add line:

cli.executable=../../node_modules/@sentry/cli/bin/sentry-cli

android/app/build.gradle

Update path to node_modules:

apply from: "../../node_modules/@sentry/react-native/sentry.gradle"

iOS: Build Phases -> Bundle React Native code and images

Update path to node_modules:

../../../node_modules/@sentry/cli/bin/sentry-cli react-native xcode \
      ../../../node_modules/react-native/scripts/react-native-xcode.sh

iOS: Build Phases -> Upload Debug Symbols to Sentry

Update path to node_modules:

    export SENTRY_PROPERTIES=sentry.properties
    ../../../node_modules/@sentry/cli/bin/sentry-cli upload-dsym

@byCedric
Copy link
Member

byCedric commented Nov 26, 2021

Hi @jamesisaac! You are correct that this is an unfortunate moment for Sentry and Expo in monorepos. You probably already seen:

We need the cli.executable to work for both Android and iOS. The reason for that is that we simply don't know where Sentry will be installed. E.g. the library can be hoisted to the root node_modules in a simple monorepo. But there are cases where it's being installed in the app's node_modules. If you use a slightly newer version of Sentry in one of your apps, or if you have multiple apps and only install sentry to one. In those cases, this won't fix the issue.

To combat that, we need a reliable solution for all monorepos. That's where the cli.executable comes into play. We can generate that during the expo prebuild phase, after everything is installed, and continue from there.

@jamesisaac
Copy link

Thanks Cedric, yeah I saw that they've now logged the cli.executable issue, but seeing as it's just 1 of 43 tickets on their To-Do Kanban I'm not sure how soon to expect that to be addressed.

Apologies if I've misunderstood the nature of Expo Config Plugins, but aren't they run before every EAS Build? In which case, couldn't some equivalent of require.resolve('@sentry/react-native/package.json') be run within the Config Plugin to determine what those node_modules paths should be set to? Agreed a simple hardcoding of paths won't work, but is the Config Plugin not able to do some introspection on the project structure?

@byCedric
Copy link
Member

byCedric commented Nov 29, 2021

Apologies if I've misunderstood the nature of Expo Config Plugins,

No worries, if you have questions I'm happy to answer it 😄

but aren't they run before every EAS Build? In which case, couldn't some equivalent of require.resolve('@sentry/react-native/package.json') be run within the Config Plugin to determine what those node_modules paths should be set to?

Partially yes, but only for managed projects. If you have an ejected project we don't regenerate your native files. We want to avoid overwriting any customizations made. It's super hard to detect these changes, that's why we stay away from that in ejected.

Agreed a simple hardcoding of paths won't work, but is the Config Plugin not able to do some introspection on the project structure?

Yes, and that's also why we need a single source of truth for this setting. If this path changes, for any reason, users should be able to quickly correct it. Not having to go through all build phases to manually edit the paths. And that's also exactly why we would need the cli.executable to be this single source of truth. It's easy to maintain and set in a config plugin, but Sentry also has to use that 🙈

@intergalacticspacehighway

Facing a similar issue after following installation steps, it's a monorepo setup.

Screenshot 2022-02-28 at 4 35 01 PM

The issue seems to be slightly different as it gets the CLI path now.
e.g. this is what we have in Bundle React native code and images step.

export SENTRY_PROPERTIES=sentry.properties
export EXTRA_PACKAGER_ARGS="--sourcemap-output $DERIVED_FILE_DIR/main.jsbundle.map"
export NODE_BINARY=node

# The project root by default is one level up from the ios directory
export PROJECT_ROOT="$PROJECT_DIR"/..

`node --print "require.resolve('@sentry/cli/package.json').slice(0, -13) + '/bin/sentry-cli'"` react-native xcode --force-foreground
`node --print "require('path').dirname(require.resolve('react-native/package.json')) + '/scripts/react-native-xcode.sh'"`

I tried debugging in react-native-xcode.sh but didn't get much success. I am not sure. Looks like the issue code be in sentry cli's react-native xcode command?

@github-actions
Copy link

This issue is stale because it has been open for 60 days with no activity. If there is no activity in the next 7 days, the issue will be closed.

@github-actions github-actions bot added the stale label Jul 19, 2022
@github-actions
Copy link

This issue was closed because it has been inactive for 7 days since being marked as stale. Please open a new issue if you believe you are encountering a related problem.

@czystyl
Copy link

czystyl commented Sep 12, 2022

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

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

No branches or pull requests

6 participants