Skip to content

SPM setup generates set -euo pipefail scripts but runs them with /bin/sh #58359

Description

@vmsp

Description

The SPM setup generates scripts that use set -euo pipefail but runs them under /bin/sh. On a machine where /bin/sh is not bash (e.g. dash), every iOS build fails before compiling anything:

SchemeScriptAction-6Thqas.sh: 2: set: Illegal option -o pipefail
** BUILD FAILED **   (xcodebuild 65)

Two places in scripts/spm/generate-spm-xcodeproj.js (line numbers on main):

  • The injected PBXShellScriptBuildPhases hardcode shellPath: '/bin/sh' (L322) while their script bodies start with set -euo pipefail (L462, L644). Fix: emit shellPath: '/bin/bash'.
  • The Sync SPM Autolinking scheme pre-action, which is the one that fails first. Xcode always runs scheme pre-actions under /bin/sh and there is no shellPath to set, so the script body itself has to be POSIX — or re-exec itself under bash.

Note that dropping -o pipefail is not sufficient for the pre-action: it also sources scripts/xcode/with-environment.sh, which uses source, another bashism dash does not have. Re-execing the pre-action under bash covers both.

Workaround for anyone hitting this: after spm add, rewrite shellPath = /bin/sh; to /bin/bash in project.pbxproj, and prepend [ -n "${BASH_VERSION-}" ] || [ ! -x /bin/bash ] || exec /bin/bash "$0" "$@" to the pre-action's scriptText in the .xcscheme.

Steps to reproduce

  1. Make /bin/sh a non-bash POSIX shell (dash). Verify with /bin/sh -c 'set -o pipefail'Illegal option -o pipefail.
  2. Create an app and run npx react-native spm add on it.
  3. xcodebuild -project App.xcodeproj -scheme App -configuration Debug -sdk iphonesimulator build
  4. The build dies in the Sync SPM Autolinking scheme pre-action, before any source file is compiled.

React Native Version

0.87.0

Affected Platforms

Build - MacOS, Runtime - iOS

Output of npx @react-native-community/cli info

System:
  OS: macOS 15.7.7
  CPU: (11) arm64 Apple M3 Pro
  Memory: 113.64 MB / 18.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 26.8.1
    path: /opt/homebrew/bin/node
  Yarn: Not Found
  npm:
    version: 11.19.0
    path: /opt/homebrew/bin/npm
  Watchman: Not Found
Managers:
  CocoaPods: Not Found
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 25.2
      - iOS 26.2
      - macOS 26.2
      - tvOS 26.2
      - visionOS 26.2
      - watchOS 26.2
  Android SDK: Not Found
IDEs:
  Android Studio: 2026.1 AI-261.26222.65.2613.16025427
  Xcode:
    version: 26.3/17C529
    path: /usr/bin/xcodebuild
Languages:
  Java: Not Found
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 19.2.8
    wanted: ^19.2.8
  react-native:
    installed: 0.87.0
    wanted: 0.87.0
  react-native-macos: Not Found

Stacktrace or Logs

SchemeScriptAction-6Thqas.sh: 2: set: Illegal option -o pipefail
** BUILD FAILED **

The following build commands failed:
	Build scheme pre-action (in target 'App' from project 'App')
(1 failure)

Reproducer

No repository link: the trigger is the machine's /bin/sh, not project code. Any RN 0.87 project set up with npx react-native spm add reproduces it once /bin/sh is dash. The generator lines are cited above, and the failure is visible without a build via /bin/sh -c 'set -o pipefail'.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: AttentionIssues where the author has responded to feedback.Needs: ReproThis issue could be improved with a clear list of steps to reproduce the issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions