From 6dcd2f7955aea42ba1bf33bfe2d93959edc9e1c7 Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Fri, 4 Dec 2026 12:15:25 +0100 Subject: [PATCH 1/3] fix(ios): Find react-native-xcode.sh in hoisted monorepos When React Native's bundle phase runs sentry-xcode.sh without an argument, use $REACT_NATIVE_PATH/scripts/react-native-xcode.sh instead of the relative ../node_modules path, which doesn't exist when react-native is hoisted to the workspace root. Keep the relative path as the last fallback. Fixes #7175 Co-Authored-By: Claude Opus 5.5 --- packages/core/scripts/sentry-xcode.sh | 9 +- .../test/scripts/sentry-xcode-scripts.test.ts | 94 +++++++++++++++++++ 2 files changed, 102 insertions(+), 1 deletion(-) diff --git a/packages/core/scripts/sentry-xcode.sh b/packages/core/scripts/sentry-xcode.sh index f1c3a4df05..8b2976f299 100755 --- a/packages/core/scripts/sentry-xcode.sh +++ b/packages/core/scripts/sentry-xcode.sh @@ -41,7 +41,14 @@ $SENTRY_CLI_ENV SENTRY_CLI_ENV_EOF set -x -REACT_NATIVE_XCODE_DEFAULT="../node_modules/react-native/scripts/react-native-xcode.sh" +# React Native's bundle phase runs this script without an argument when REACT_NATIVE_XCODE points at it. +# Prefer REACT_NATIVE_PATH (set by the phase) so hoisted monorepos, where react-native is not in +# ../node_modules, find the script. See https://github.com/getsentry/sentry-react-native/issues/7175 +if [ -n "$REACT_NATIVE_PATH" ]; then + REACT_NATIVE_XCODE_DEFAULT="$REACT_NATIVE_PATH/scripts/react-native-xcode.sh" +else + REACT_NATIVE_XCODE_DEFAULT="../node_modules/react-native/scripts/react-native-xcode.sh" +fi REACT_NATIVE_XCODE="${1:-$REACT_NATIVE_XCODE_DEFAULT}" [[ "$AUTO_RELEASE" == false ]] && [[ -z "$BUNDLE_COMMAND" || "$BUNDLE_COMMAND" != "ram-bundle" ]] && NO_AUTO_RELEASE="--no-auto-release" diff --git a/packages/core/test/scripts/sentry-xcode-scripts.test.ts b/packages/core/test/scripts/sentry-xcode-scripts.test.ts index c9bb824c06..731f25a0b9 100644 --- a/packages/core/test/scripts/sentry-xcode-scripts.test.ts +++ b/packages/core/test/scripts/sentry-xcode-scripts.test.ts @@ -501,6 +501,100 @@ describe('sentry-xcode.sh', () => { expect(args.slice(-2)).toEqual(['--build-script', mockReactNativeScript]); }); + describe('React Native script resolution without an argument (issue #7175)', () => { + // React Native's bundle phase runs `$WITH_ENVIRONMENT $REACT_NATIVE_XCODE`, so when + // REACT_NATIVE_XCODE points at sentry-xcode.sh the script gets no argument. + const writeRnScript = (dir: string, message: string): string => { + const scriptsDir = path.join(dir, 'scripts'); + fs.mkdirSync(scriptsDir, { recursive: true }); + const script = path.join(scriptsDir, 'react-native-xcode.sh'); + fs.writeFileSync(script, `#!/bin/bash\necho "${message}"\nexit 0\n`); + fs.chmodSync(script, '755'); + return script; + }; + + const runWithoutArg = (cwd: string, env: Record = {}) => { + const mockCollectModulesScript = path.join(tempDir, 'collect-modules.sh'); + fs.writeFileSync(mockCollectModulesScript, '#!/bin/bash\nexit 0\n'); + fs.chmodSync(mockCollectModulesScript, '755'); + const childEnv: Record = { + ...process.env, + NODE_BINARY: process.execPath, + SENTRY_CLI_EXECUTABLE: mockSentryCliScript, + PROJECT_DIR: cwd, + DERIVED_FILE_DIR: tempDir, + SENTRY_COLLECT_MODULES: mockCollectModulesScript, + SENTRY_DISABLE_AUTO_UPLOAD: 'true', + ...env, + }; + if (!('REACT_NATIVE_PATH' in env)) { + delete childEnv.REACT_NATIVE_PATH; + } + const result = spawnSync('bash', [XCODE_SCRIPT], { cwd, env: childEnv, encoding: 'utf8' }); + return { stdout: result.stdout, stderr: result.stderr, exitCode: result.status }; + }; + + // Hoisted monorepo: /node_modules/react-native, app in /apps/mobile/ios. + const makeHoistedMonorepo = () => { + const root = path.join(tempDir, 'monorepo'); + const iosDir = path.join(root, 'apps', 'mobile', 'ios'); + fs.mkdirSync(iosDir, { recursive: true }); + const reactNativePath = path.join(root, 'node_modules', 'react-native'); + writeRnScript(reactNativePath, 'Hoisted React Native bundle'); + return { iosDir, reactNativePath }; + }; + + it('runs the script from REACT_NATIVE_PATH in a hoisted monorepo', () => { + const { iosDir, reactNativePath } = makeHoistedMonorepo(); + + const result = runWithoutArg(iosDir, { REACT_NATIVE_PATH: reactNativePath }); + + expect(result.exitCode).toBe(0); + expect(result.stdout).toContain('Hoisted React Native bundle'); + }); + + it('runs the script from REACT_NATIVE_PATH for the upload', () => { + const { iosDir, reactNativePath } = makeHoistedMonorepo(); + const echoScript = path.join(tempDir, 'mock-sentry-cli-echo-args.js'); + fs.writeFileSync(echoScript, "console.log('ARGS=' + JSON.stringify(process.argv.slice(2)));"); + + const result = runWithoutArg(iosDir, { + REACT_NATIVE_PATH: reactNativePath, + SENTRY_DISABLE_AUTO_UPLOAD: 'false', + SENTRY_CLI_EXECUTABLE: echoScript, + }); + + expect(result.exitCode).toBe(0); + const args: string[] = JSON.parse(/ARGS=(.+)/.exec(result.stdout)![1]); + expect(args.slice(-2)).toEqual([ + '--build-script', + path.join(reactNativePath, 'scripts', 'react-native-xcode.sh'), + ]); + }); + + it('falls back to ../node_modules/react-native when REACT_NATIVE_PATH is not set', () => { + const appRoot = path.join(tempDir, 'app'); + const iosDir = path.join(appRoot, 'ios'); + fs.mkdirSync(iosDir, { recursive: true }); + writeRnScript(path.join(appRoot, 'node_modules', 'react-native'), 'Relative React Native bundle'); + + const result = runWithoutArg(iosDir); + + expect(result.exitCode).toBe(0); + expect(result.stdout).toContain('Relative React Native bundle'); + }); + + it('prefers the script passed as an argument over REACT_NATIVE_PATH', () => { + const { reactNativePath } = makeHoistedMonorepo(); + + const result = runScript({ REACT_NATIVE_PATH: reactNativePath, SENTRY_DISABLE_AUTO_UPLOAD: 'true' }); + + expect(result.exitCode).toBe(0); + expect(result.stdout).toContain('Mock React Native bundle'); + expect(result.stdout).not.toContain('Hoisted React Native bundle'); + }); + }); + describe('project path containing spaces (issue #6583)', () => { // Put react-native-xcode.sh in a directory whose path contains a space. The disable and Debug // branches re-parse REACT_NATIVE_XCODE via `/bin/sh -c`, which word-splits on the space unless From 3c55d93261297bd9aa4d03af08fc3b37ea949d96 Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Fri, 4 Dec 2026 12:15:47 +0100 Subject: [PATCH 2/3] chore: Add changelog entry for #7182 Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7b08caeb2..b59a3a4d54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,10 @@ - The v4 CLI uses a self-hosted `url` from `.sentryclirc` only with credentials for that server, otherwise it stops with exit code 13. Its exit codes for other failures also differ from v3. - The v4 CLI sends usage and error telemetry about itself to Sentry. Set `SENTRY_CLI_NO_TELEMETRY=1` or `DO_NOT_TRACK=1` in the build environment to opt out. +### Fixes + +- Fix the iOS Release build failing in hoisted monorepos because `sentry-xcode.sh` looked for React Native in `../node_modules` ([#7182](https://github.com/getsentry/sentry-react-native/pull/7182)) + ### Dependencies - Bump CLI from v3.8.2 to v4.0.1 ([#7177](https://github.com/getsentry/sentry-react-native/pull/7177), [#7180](https://github.com/getsentry/sentry-react-native/pull/7180)) From 929e8488f9df947708ce8ef692fcc621e1532d78 Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Fri, 4 Dec 2026 12:30:56 +0100 Subject: [PATCH 3/3] fix(ios): Use REACT_NATIVE_PATH only if react-native-xcode.sh exists there Fall back to ../node_modules/react-native when REACT_NATIVE_PATH is stale or unrelated, so setups that built before the fix keep building. Co-Authored-By: Claude Opus 5.5 --- packages/core/scripts/sentry-xcode.sh | 7 ++++--- .../core/test/scripts/sentry-xcode-scripts.test.ts | 13 +++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/core/scripts/sentry-xcode.sh b/packages/core/scripts/sentry-xcode.sh index 8b2976f299..792a2c5f2d 100755 --- a/packages/core/scripts/sentry-xcode.sh +++ b/packages/core/scripts/sentry-xcode.sh @@ -42,9 +42,10 @@ SENTRY_CLI_ENV_EOF set -x # React Native's bundle phase runs this script without an argument when REACT_NATIVE_XCODE points at it. -# Prefer REACT_NATIVE_PATH (set by the phase) so hoisted monorepos, where react-native is not in -# ../node_modules, find the script. See https://github.com/getsentry/sentry-react-native/issues/7175 -if [ -n "$REACT_NATIVE_PATH" ]; then +# Prefer the script in REACT_NATIVE_PATH, the build setting React Native's CocoaPods setup writes (0.69+), +# so hoisted monorepos, where react-native is not in ../node_modules, find it. Only use it if the script +# exists there. See https://github.com/getsentry/sentry-react-native/issues/7175 +if [ -n "$REACT_NATIVE_PATH" ] && [ -f "$REACT_NATIVE_PATH/scripts/react-native-xcode.sh" ]; then REACT_NATIVE_XCODE_DEFAULT="$REACT_NATIVE_PATH/scripts/react-native-xcode.sh" else REACT_NATIVE_XCODE_DEFAULT="../node_modules/react-native/scripts/react-native-xcode.sh" diff --git a/packages/core/test/scripts/sentry-xcode-scripts.test.ts b/packages/core/test/scripts/sentry-xcode-scripts.test.ts index 731f25a0b9..4055a2e261 100644 --- a/packages/core/test/scripts/sentry-xcode-scripts.test.ts +++ b/packages/core/test/scripts/sentry-xcode-scripts.test.ts @@ -584,6 +584,19 @@ describe('sentry-xcode.sh', () => { expect(result.stdout).toContain('Relative React Native bundle'); }); + it('falls back to ../node_modules/react-native when REACT_NATIVE_PATH has no React Native script', () => { + const appRoot = path.join(tempDir, 'app'); + const iosDir = path.join(appRoot, 'ios'); + fs.mkdirSync(iosDir, { recursive: true }); + writeRnScript(path.join(appRoot, 'node_modules', 'react-native'), 'Relative React Native bundle'); + const staleReactNativePath = path.join(tempDir, 'moved', 'node_modules', 'react-native'); + + const result = runWithoutArg(iosDir, { REACT_NATIVE_PATH: staleReactNativePath }); + + expect(result.exitCode).toBe(0); + expect(result.stdout).toContain('Relative React Native bundle'); + }); + it('prefers the script passed as an argument over REACT_NATIVE_PATH', () => { const { reactNativePath } = makeHoistedMonorepo();