question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using `@bugsnag/react-native` in monorepo

See original GitHub issue

This is not so much of a feature request but more to consult with maintainers how to fix a problem I faced trying to use it in monorepo environment. I don’t mind opening PR (as long as we reach a conclusion soon and I’m still in the loop 😃 )

Description

I am working on react-native app located inside learna managed monorepo. When I tried to upgrade to version 7 or bugsnag-js I started seeing lots of errors like https://github.com/bugsnag/bugsnag-js/issues/1255 :

   > Could not find com.bugsnag:bugsnag-android:5.5.1-react-native.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/com/bugsnag/bugsnag-android/5.5.1-react-native/bugsnag-android-5.5.1-react-native.pom
       - https://dl.google.com/dl/android/maven2/com/bugsnag/bugsnag-android/5.5.1-react-native/bugsnag-android-5.5.1-react-native.jar
       - https://maven.google.com/com/bugsnag/bugsnag-android/5.5.1-react-native/bugsnag-android-5.5.1-react-native.pom
       - https://maven.google.com/com/bugsnag/bugsnag-android/5.5.1-react-native/bugsnag-android-5.5.1-react-native.jar
       - .....

eventually after reading these lines https://github.com/bugsnag/bugsnag-js/blob/8e142100e20880500c1d374871b6b7871aec1db6/packages/react-native/android/build.gradle#L51-L67 I figured a plugin makes certain assumptions about paths in a project which were not true in case of a package under packages/.... in a typical lerna monorepo.

I managed to fix these errors by adding

    dependencies {
        maven {
            url "$rootDir/../../../node_modules/@bugsnag/react-native/android"
        }
    }

to my packages/app/android/build.gradle

Describe the solution you’d like

I would like this project to be easier to use in monorepo environment.

Describe alternatives you’ve considered

I consider 2 options which are good enough for me:

  1. https://github.com/bugsnag/bugsnag-js/blob/next/packages/react-native/android/build.gradle could be smarter about layout of directories (which I understand would be an assumption on it’s own)
  2. or simply add few lines into readme explaining how to fix these errors

Additional context

thanks

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
johnkiely1commented, Apr 7, 2021

Hi @MohammadAzimi,

The bugsnag { } configuration should be in its own section outside of the android block.

With regards the error you see if you do that, have you added the line

apply plugin: "com.bugsnag.android.gradle"

after

apply from: "../../../node_modules/react-native/react.gradle" within that file?

https://docs.bugsnag.com/platforms/react-native/react-native/manual-setup/#android

1reaction
xljonescommented, Mar 4, 2021

As of https://github.com/bugsnag/bugsnag-android-gradle-plugin/releases/tag/v5.7.4 you can now specify where your node_modules directory is using the nodeModulesDir Gradle configuration option which will allow you to use @bugsnag/react-native in a monorepo.

Update your Bugsnag Android Gradle Plugin dependency to v5.7.4. Then, in your app’s build.gradle file, add to your bugsnag config:

bugsnag {
	// relative to the project directory
    nodeModulesDir = project.layout.projectDirectory.dir("../../../node_modules/").asFile
	// or using an absolute path
	nodeModulesDir = new File("/custom-path/node_modules")
	// ...
}

https://docs.bugsnag.com/build-integrations/gradle/#custom-node_modules-directory

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bundle errors when setting up react-native in monorepo
I'm having some issues setting up a new react-native project inside a yarn monorepo with workspaces. My root package.json looks like:
Read more >
React Native integration guide
The easiest way to add Bugsnag to your React Native project is to use our CLI (macOS ... If you're using @bugsnag/react-native in...
Read more >
bugsnag-js/UPGRADING.md at next - react-native
As of v7.3 of the bugsnag-js monorepo it contains Bugsnag's SDK for React ... or continue to use bugsnag-react-native until such time as...
Read more >
How to Create a React Typescript Monorepo with Git ...
This tutorial requires yarn v1 installed (we use v1.22). Initializing the Project. To start, we need a packages directory to hold the different ......
Read more >
Setting up React Native Monorepo with Yarn Workspaces
Monorepos enable sharing the logic between a web app and a mobile app, for example. In this article, we're going to set up...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found