Skip to content

Resolve sentry-cli relative to @sentry/react-native in isolated dependency layouts #6241

@shawnthye-guru

Description

@shawnthye-guru

What React Native libraries do you use?

React Native / Expo, with pnpm workspace dependency layout

Are you using sentry.io or on-premise?

sentry.io (SaaS)

@sentry/react-native SDK Version

Observed with @sentry/react-native@7.11.0; current main still has the same direct resolver pattern in packages/core/sentry.gradle.kts and both iOS scripts.

Description

The Android Gradle integration and iOS Xcode scripts try to locate @sentry/cli with a direct Node resolution from the native project directory:

require.resolve('@sentry/cli/package.json')

That does not work reliably with package managers that isolate dependencies, such as pnpm. @sentry/cli is installed as a dependency of @sentry/react-native, but it is not necessarily directly resolvable from android/ or ios/.

Resolving the CLI from the @sentry/react-native package context works in this layout:

require.resolve('@sentry/cli/package.json', {
  paths: [require.resolve('@sentry/react-native/package.json')],
})

Steps to Reproduce

  1. Use a pnpm workspace React Native app with @sentry/react-native installed.
  2. Do not install @sentry/cli as a direct app dependency.
  3. Run the resolver from a native project directory such as android/ or ios/:
node --print "require.resolve('@sentry/cli/package.json')"
  1. Compare that with dependency-relative resolution:
node --print "require.resolve('@sentry/cli/package.json', { paths: [require.resolve('@sentry/react-native/package.json')] })"

Expected Result

The native Android and iOS integrations should resolve the sentry-cli package shipped through @sentry/react-native without requiring applications to add @sentry/cli as a direct dependency or set a manual executable override.

Actual Result

Plain require.resolve('@sentry/cli/package.json') can fail with:

Error: Cannot find module '@sentry/cli/package.json'
Require stack:
- /path/to/app/android/[eval]

The dependency-relative resolver returns the installed pnpm store path for @sentry/cli, allowing the scripts to compute bin/sentry-cli correctly.

Proposed Fix

Use dependency-relative resolution in:

  • packages/core/sentry.gradle.kts
  • packages/core/scripts/sentry-xcode.sh
  • packages/core/scripts/sentry-xcode-debug-files.sh

The existing pnpm shim fallback can stay in place as a fallback path.

Related

Metadata

Metadata

Assignees

No one assigned
    No fields configured for issues without a type.

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions