Skip to content

Fix SDK Build when using PnPM #4977

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

Merged
merged 6 commits into from
Jul 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

### Fixes

- SDK now Builds when using PnPM ([#4977](https://github.com/getsentry/sentry-react-native/pull/4977))
- Skip idle span creation when app is in background ([#4995](https://github.com/getsentry/sentry-react-native/pull/4995))

### Dependencies
Expand Down
24 changes: 23 additions & 1 deletion packages/core/scripts/sentry-xcode-debug-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,29 @@ RN_PROJECT_ROOT="${PROJECT_DIR}/.."
[ -z "$SENTRY_DOTENV_PATH" ] && export SENTRY_DOTENV_PATH="$RN_PROJECT_ROOT/.env.sentry-build-plugin"

[ -z "$SENTRY_CLI_EXECUTABLE" ] && SENTRY_CLI_PACKAGE_PATH=$("$LOCAL_NODE_BINARY" --print "require('path').dirname(require.resolve('@sentry/cli/package.json'))")
[ -z "$SENTRY_CLI_EXECUTABLE" ] && SENTRY_CLI_EXECUTABLE="${SENTRY_CLI_PACKAGE_PATH}/bin/sentry-cli"
[ -z "$SOURCEMAP_FILE" ] && export SOURCEMAP_FILE="$DERIVED_FILE_DIR/main.jsbundle.map"

if [ -z "$SENTRY_CLI_EXECUTABLE" ]; then
# Try standard resolution safely
RESOLVED_PATH=$(
"$LOCAL_NODE_BINARY" --print "require('path').dirname(require.resolve('@sentry/cli/package.json'))" 2>/dev/null
) || true
if [ -n "$RESOLVED_PATH" ]; then
SENTRY_CLI_PACKAGE_PATH="$RESOLVED_PATH"
else
# Fallback: parse NODE_PATH from the .bin/sentry-cli shim (file generated by PNPM)
PNPM_BIN_PATH="$PWD/../node_modules/@sentry/react-native/node_modules/.bin/sentry-cli"

if [ -f "$PNPM_BIN_PATH" ]; then
CLI_FILE_TEXT=$(cat "$PNPM_BIN_PATH")

# Filter where PNPM stored Sentry CLI
NODE_PATH_LINE=$(echo "$CLI_FILE_TEXT" | grep -oE 'NODE_PATH="[^"]+"' | head -n1)
NODE_PATH_VALUE=$(echo "$NODE_PATH_LINE" | sed -E 's/^NODE_PATH="([^"]+)".*/\1/')
SENTRY_CLI_PACKAGE_PATH=${NODE_PATH_VALUE%%/bin*}
fi
fi
fi

[[ $SENTRY_INCLUDE_NATIVE_SOURCES == "true" ]] && INCLUDE_SOURCES_FLAG="--include-sources" || INCLUDE_SOURCES_FLAG=""

Expand Down
22 changes: 21 additions & 1 deletion packages/core/scripts/sentry-xcode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,27 @@ RN_PROJECT_ROOT="${PROJECT_DIR}/.."
[ -z "$SENTRY_DOTENV_PATH" ] && export SENTRY_DOTENV_PATH="$RN_PROJECT_ROOT/.env.sentry-build-plugin"
[ -z "$SOURCEMAP_FILE" ] && export SOURCEMAP_FILE="$DERIVED_FILE_DIR/main.jsbundle.map"

[ -z "$SENTRY_CLI_EXECUTABLE" ] && SENTRY_CLI_PACKAGE_PATH=$("$LOCAL_NODE_BINARY" --print "require('path').dirname(require.resolve('@sentry/cli/package.json'))")
if [ -z "$SENTRY_CLI_EXECUTABLE" ]; then
# Try standard resolution safely
RESOLVED_PATH=$(
"$LOCAL_NODE_BINARY" --print "require('path').dirname(require.resolve('@sentry/cli/package.json'))" 2>/dev/null
) || true
if [ -n "$RESOLVED_PATH" ]; then
SENTRY_CLI_PACKAGE_PATH="$RESOLVED_PATH"
else
# Fallback: parse NODE_PATH from the .bin/sentry-cli shim (file generated by PNPM)
PNPM_BIN_PATH="$PWD/../node_modules/@sentry/react-native/node_modules/.bin/sentry-cli"

if [ -f "$PNPM_BIN_PATH" ]; then
CLI_FILE_TEXT=$(cat "$PNPM_BIN_PATH")

# Filter where PNPM stored Sentry CLI
NODE_PATH_LINE=$(echo "$CLI_FILE_TEXT" | grep -oE 'NODE_PATH="[^"]+"' | head -n1)
NODE_PATH_VALUE=$(echo "$NODE_PATH_LINE" | sed -E 's/^NODE_PATH="([^"]+)".*/\1/')
SENTRY_CLI_PACKAGE_PATH=${NODE_PATH_VALUE%%/bin*}
fi
fi
fi
[ -z "$SENTRY_CLI_EXECUTABLE" ] && SENTRY_CLI_EXECUTABLE="${SENTRY_CLI_PACKAGE_PATH}/bin/sentry-cli"

REACT_NATIVE_XCODE=$1
Expand Down
32 changes: 27 additions & 5 deletions packages/core/sentry.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,7 @@ project.afterEvaluate {
project.logger.info("file not found '$propertiesFile' for '$variant'")
}

def resolvedCliPackage = null
try {
resolvedCliPackage = new File(["node", "--print", "require.resolve('@sentry/cli/package.json')"].execute(null, rootDir).text.trim()).getParentFile();
} catch (Throwable ignored) {}
def cliPackage = resolvedCliPackage != null && resolvedCliPackage.exists() ? resolvedCliPackage.getAbsolutePath() : "$reactRoot/node_modules/@sentry/cli"
def cliPackage = resolveSentryCliPackagePath(reactRoot)
def cliExecutable = sentryProps.get("cli.executable", "$cliPackage/bin/sentry-cli")

// fix path separator for Windows
Expand Down Expand Up @@ -306,6 +302,32 @@ def resolveSentryReactNativeSDKPath(reactRoot) {
return sentryPackage
}

def resolveSentryCliPackagePath(reactRoot) {
def resolvedCliPath = null
try {
def file = new File(["node", "--print", "require.resolve('@sentry/cli/package.json')"].execute(null, rootDir))
resolvedCliPath = file.text.trim().getParentFile();
} catch (Throwable ignored) { // Check if it's located in .pnpm
try {
def pnpmRefPath = reactRoot.toString() + "/node_modules/@sentry/react-native/node_modules/.bin/sentry-cli"
def sentryCliFile = new File(pnpmRefPath)

if (sentryCliFile.exists()) {
def cliFileText = sentryCliFile.text
def matcher = cliFileText =~ /NODE_PATH="([^"]*?)@sentry\/cli\//

if (matcher.find()) {
def match = matcher.group(1)
resolvedCliPath = new File(match + "@sentry/cli")
}
}
} catch (Throwable ignored2) {} // if the resolve fails we fallback to the default path
}

def cliPackage = resolvedCliPath != null && resolvedCliPath.exists() ? resolvedCliPath.getAbsolutePath() : "$reactRoot/node_modules/@sentry/cli"
return cliPackage
}

/** Compose lookup map of build variants - to - outputs. */
def extractReleasesInfo() {
def releases = [:]
Expand Down
Loading