'Running default RN native project in iOS gives error

Any idea what is going wrong? I have updated all the relevant components to their latest version.

I am creating a default react-native project and trying to run the iOS simulator

npx react-native init {project_name}
cd {project_name}
npx react-native run-ios    

I receive the following error:

/bin/sh -c {user}/Library/Developer/Xcode/DerivedData/{project_name}-epegcqhmisnuaeenegumkazvqqys/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/FBReactNativeSpec.build/Script-5F4C70EF7D90A5A5BDAEB404279F232A.sh
N/A: version "default -> N/A" is not yet installed.

You need to run "nvm install default" to install it before using it.
Command PhaseScriptExecution failed with a nonzero exit code

The script (self-generated) in question is below:

#!/bin/sh
set -o pipefail
set -e

RN_DIR=$(cd "${PODS_TARGET_SRCROOT}/../.." && pwd)

GENERATED_SRCS_DIR="${DERIVED_FILE_DIR}/generated/source/codegen"
GENERATED_SCHEMA_FILE="$GENERATED_SRCS_DIR/schema.json"
TEMP_OUTPUT_DIR="$GENERATED_SRCS_DIR/out"

LIBRARY_NAME="FBReactNativeSpec"
OUTPUT_DIR="${PODS_TARGET_SRCROOT}/../../React/FBReactNativeSpec/FBReactNativeSpec"

CODEGEN_REPO_PATH="$RN_DIR/packages/react-native-codegen"
CODEGEN_NPM_PATH="$RN_DIR/../react-native-codegen"
CODEGEN_CLI_PATH=""

# Determine path to react-native-codegen
if [ -d "$CODEGEN_REPO_PATH" ]; then
  CODEGEN_CLI_PATH=$(cd "$CODEGEN_REPO_PATH" && pwd)
elif [ -d "$CODEGEN_NPM_PATH" ]; then
  CODEGEN_CLI_PATH=$(cd "$CODEGEN_NPM_PATH" && pwd)
else
  echo "error: Could not determine react-native-codegen location. Try running 'yarn install' or 'npm install' in your project root." >> "${SCRIPT_OUTPUT_FILE_0}" 2>&1
  exit 1
fi

find_node () {
  source "$RN_DIR/scripts/find-node.sh"

  NODE_BINARY="${NODE_BINARY:-$(command -v node || true)}"
  if [ -z "$NODE_BINARY" ]; then
    echo "error: Could not find node. Make sure it is in bash PATH or set the NODE_BINARY environment variable." >> "${SCRIPT_OUTPUT_FILE_0}" 2>&1
    exit 1
  fi
}

setup_dirs () {
  set +e
  rm -rf "$GENERATED_SRCS_DIR"
  set -e

  mkdir -p "$GENERATED_SRCS_DIR" "$TEMP_OUTPUT_DIR"

  # Clear output files
  > "${SCRIPT_OUTPUT_FILE_0}"
}

describe () {
  printf "\n\n>>>>> %s\n\n\n" "$1" >> "${SCRIPT_OUTPUT_FILE_0}" 2>&1
}

buildCodegenCLI () {
  if [ ! -d "$CODEGEN_CLI_PATH/lib" ]; then
    describe "Building react-native-codegen package"
    bash "$CODEGEN_CLI_PATH/scripts/oss/build.sh"
  fi
}

generateCodegenSchemaFromJavaScript () {
  describe "Generating codegen schema from JavaScript"

  SRCS_PATTERN="Native*.js"
  SRCS_DIR="../../Libraries"
  if [ $SRCS_PATTERN ]; then
    JS_SRCS=$(find "${PODS_TARGET_SRCROOT}"/$SRCS_DIR -type f -name "$SRCS_PATTERN" -print0 | xargs -0)
    echo "["../../Libraries/ActionSheetIOS/NativeActionSheetManager.js", "../../Libraries/Alert/NativeAlertManager.js", "../../Libraries/Animated/NativeAnimatedHelper.js", "../../Libraries/Animated/NativeAnimatedModule.js", "../../Libraries/Animated/NativeAnimatedTurboModule.js", "../../Libraries/AppState/NativeAppState.js", "../../Libraries/BatchedBridge/NativeModules.js", "../../Libraries/Blob/NativeBlobModule.js", "../../Libraries/Blob/NativeFileReaderModule.js", "../../Libraries/BugReporting/NativeBugReporting.js", "../../Libraries/Components/AccessibilityInfo/NativeAccessibilityInfo.js", "../../Libraries/Components/AccessibilityInfo/NativeAccessibilityManager.js", "../../Libraries/Components/Clipboard/NativeClipboard.js", "../../Libraries/Components/DatePickerAndroid/NativeDatePickerAndroid.js", "../../Libraries/Components/Keyboard/NativeKeyboardObserver.js", "../../Libraries/Components/Sound/NativeSoundManager.js", "../../Libraries/Components/StatusBar/NativeStatusBarManagerAndroid.js", "../../Libraries/Components/StatusBar/NativeStatusBarManagerIOS.js", "../../Libraries/Components/ToastAndroid/NativeToastAndroid.js", "../../Libraries/Core/NativeExceptionsManager.js", "../../Libraries/Core/SegmentFetcher/NativeSegmentFetcher.js", "../../Libraries/Core/Timers/NativeTiming.js", "../../Libraries/EventEmitter/NativeEventEmitter.js", "../../Libraries/EventEmitter/__mocks__/NativeEventEmitter.js", "../../Libraries/HeapCapture/NativeJSCHeapCapture.js", "../../Libraries/Image/NativeImageEditor.js", "../../Libraries/Image/NativeImageLoaderAndroid.js", "../../Libraries/Image/NativeImageLoaderIOS.js", "../../Libraries/Image/NativeImagePickerIOS.js", "../../Libraries/Image/NativeImageStoreAndroid.js", "../../Libraries/Image/NativeImageStoreIOS.js", "../../Libraries/Interaction/NativeFrameRateLogger.js", "../../Libraries/Linking/NativeIntentAndroid.js", "../../Libraries/Linking/NativeLinkingManager.js", "../../Libraries/Modal/NativeModalManager.js", "../../Libraries/NativeComponent/NativeComponentRegistry.js", "../../Libraries/NativeModules/specs/NativeAnimationsDebugModule.js", "../../Libraries/NativeModules/specs/NativeDevMenu.js", "../../Libraries/NativeModules/specs/NativeDevSettings.js", "../../Libraries/NativeModules/specs/NativeDeviceEventManager.js", "../../Libraries/NativeModules/specs/NativeDialogManagerAndroid.js", "../../Libraries/NativeModules/specs/NativeLogBox.js", "../../Libraries/NativeModules/specs/NativeRedBox.js", "../../Libraries/NativeModules/specs/NativeSourceCode.js", "../../Libraries/Network/NativeNetworkingAndroid.js", "../../Libraries/Network/NativeNetworkingIOS.js", "../../Libraries/Performance/NativeJSCSamplingProfiler.js", "../../Libraries/PermissionsAndroid/NativePermissionsAndroid.js", "../../Libraries/PushNotificationIOS/NativePushNotificationManagerIOS.js", "../../Libraries/ReactNative/NativeHeadlessJsTaskSupport.js", "../../Libraries/ReactNative/NativeI18nManager.js", "../../Libraries/ReactNative/NativeUIManager.js", "../../Libraries/Settings/NativeSettingsManager.js", "../../Libraries/Share/NativeShareModule.js", "../../Libraries/Storage/NativeAsyncLocalStorage.js", "../../Libraries/Storage/NativeAsyncSQLiteDBStorage.js", "../../Libraries/TurboModule/samples/NativeSampleTurboModule.js", "../../Libraries/Utilities/NativeAppearance.js", "../../Libraries/Utilities/NativeDevLoadingView.js", "../../Libraries/Utilities/NativeDevSplitBundleLoader.js", "../../Libraries/Utilities/NativeDeviceInfo.js", "../../Libraries/Utilities/NativeJSDevSupport.js", "../../Libraries/Utilities/NativePlatformConstantsAndroid.js", "../../Libraries/Utilities/NativePlatformConstantsIOS.js", "../../Libraries/Vibration/NativeVibration.js", "../../Libraries/WebSocket/NativeWebSocketModule.js"]" >> "${SCRIPT_OUTPUT_FILE_0}" 2>&1
  else
    JS_SRCS="${PODS_TARGET_SRCROOT}/$SRCS_DIR"
    echo "../../Libraries" >> "${SCRIPT_OUTPUT_FILE_0}" 2>&1
  fi

  "$NODE_BINARY" "$CODEGEN_CLI_PATH/lib/cli/combine/combine-js-to-schema-cli.js" "$GENERATED_SCHEMA_FILE" $JS_SRCS
}

generateCodegenArtifactsFromSchema () {
  describe "Generating codegen artifacts from schema"
  pushd "$RN_DIR" >/dev/null || exit 1
    "$NODE_BINARY" "scripts/generate-specs-cli.js" ios "$GENERATED_SCHEMA_FILE" "$TEMP_OUTPUT_DIR" "$LIBRARY_NAME"
  popd >/dev/null || exit 1
}

moveOutputs () {
  mkdir -p "$OUTPUT_DIR"

  # Copy all output to output_dir
  cp -R "$TEMP_OUTPUT_DIR/" "$OUTPUT_DIR" || exit 1
  echo "$LIBRARY_NAME output has been written to $OUTPUT_DIR:" >> "${SCRIPT_OUTPUT_FILE_0}" 2>&1
  ls -1 "$OUTPUT_DIR" >> "${SCRIPT_OUTPUT_FILE_0}" 2>&1
}

main () {
  setup_dirs
  find_node
  buildCodegenCLI
  generateCodegenSchemaFromJavaScript
  generateCodegenArtifactsFromSchema
  moveOutputs
}

main "$@"
echo 'Done.' >> "${SCRIPT_OUTPUT_FILE_0}" 2>&1

Trying to run from Xcode yields in the same error.

Needless to say, I tried running

nvm install default

and received the following error:

Version 'default' not found - try `nvm ls-remote` to browse available versions.


Solution 1:[1]

I don't answer on Stackoverflow often but I had the same issue and used this post to solve it.

It basically revolves around the command

nvm alias default system

or swapping system to whatever version of NodeJS you would like.

Solution 2:[2]

Rather than modifying the system node, applying the commit that removes the find-node.sh script with patch-package fixed this issue for a dev on our team who was stuck with this issue.

The contents of our patch is simply

diff --git a/node_modules/react-native/scripts/find-node.sh b/node_modules/react-native/scripts/find-node.sh
deleted file mode 100755
index 5d6d2c4..0000000
--- a/node_modules/react-native/scripts/find-node.sh
+++ /dev/null
@@ -1,56 +0,0 @@
-#!/bin/bash
-# Copyright (c) Facebook, Inc. and its affiliates.
-#
-# This source code is licensed under the MIT license found in the
-# LICENSE file in the root directory of this source tree.
-
-set -e
-
-# remove global prefix if it's already set
-# the running shell process will choose a node binary and a global package directory breaks version managers
-unset PREFIX
-
-# Support Homebrew on M1
-HOMEBREW_M1_BIN=/opt/homebrew/bin
-if [[ -d $HOMEBREW_M1_BIN && ! $PATH =~ $HOMEBREW_M1_BIN ]]; then
-  export PATH="$HOMEBREW_M1_BIN:$PATH"
-fi
-
-# Define NVM_DIR and source the nvm.sh setup script
-[ -z "$NVM_DIR" ] && export NVM_DIR="$HOME/.nvm"
-
-# Source nvm with '--no-use' and then `nvm use` to respect .nvmrc
-# See: https://github.com/nvm-sh/nvm/issues/2053
-if [[ -s "$HOME/.nvm/nvm.sh" ]]; then
-  # shellcheck source=/dev/null
-  . "$HOME/.nvm/nvm.sh" --no-use
-  nvm use 2> /dev/null || nvm use default
-elif [[ -x "$(command -v brew)" && -s "$(brew --prefix nvm)/nvm.sh" ]]; then
-  # shellcheck source=/dev/null
-  . "$(brew --prefix nvm)/nvm.sh" --no-use
-  nvm use 2> /dev/null || nvm use default
-fi
-
-# Set up the nodenv node version manager if present
-if [[ -x "$HOME/.nodenv/bin/nodenv" ]]; then
-  eval "$("$HOME/.nodenv/bin/nodenv" init -)"
-elif [[ -x "$(command -v brew)" && -x "$(brew --prefix nodenv)/bin/nodenv" ]]; then
-  eval "$("$(brew --prefix nodenv)/bin/nodenv" init -)"
-fi
-
-# Set up the ndenv of anyenv if preset
-if [[ ! -x node && -d ${HOME}/.anyenv/bin ]]; then
-  export PATH=${HOME}/.anyenv/bin:${PATH}
-  if [[ "$(anyenv envs | grep -c ndenv )" -eq 1 ]]; then
-    eval "$(anyenv init -)"
-  fi
-fi
-
-# Set up asdf-vm if present
-if [[ -f "$HOME/.asdf/asdf.sh" ]]; then
-  # shellcheck source=/dev/null
-  . "$HOME/.asdf/asdf.sh"
-elif [[ -x "$(command -v brew)" && -f "$(brew --prefix asdf)/asdf.sh" ]]; then
-  # shellcheck source=/dev/null
-  . "$(brew --prefix asdf)/asdf.sh"
-fi
diff --git a/node_modules/react-native/scripts/react-native-xcode.sh b/node_modules/react-native/scripts/react-native-xcode.sh
index 3ef9a71..304a5dc 100755
--- a/node_modules/react-native/scripts/react-native-xcode.sh
+++ b/node_modules/react-native/scripts/react-native-xcode.sh
@@ -79,9 +79,7 @@ if [[ $DEV != true && ! -f "$ENTRY_FILE" ]]; then
   exit 2
 fi
 
-# Find path to Node
-# shellcheck source=/dev/null
-source "$REACT_NATIVE_DIR/scripts/find-node.sh"
+NODE_BINARY="$(command -v node)"
 
 # check and assign NODE_BINARY env
 # shellcheck source=/dev/null
diff --git a/node_modules/react-native/scripts/react_native_pods.rb b/node_modules/react-native/scripts/react_native_pods.rb
index 1b8a078..d65c9ca 100644
--- a/node_modules/react-native/scripts/react_native_pods.rb
+++ b/node_modules/react-native/scripts/react_native_pods.rb
@@ -289,8 +289,6 @@ else
 fi
 
 find_node () {
-  source "$RN_DIR/scripts/find-node.sh"
-
   NODE_BINARY="${NODE_BINARY:-$(command -v node || true)}"
   if [ -z "$NODE_BINARY" ]; then
     echo "error: Could not find node. Make sure it is in bash PATH or set the NODE_BINARY environment variable." >> "${SCRIPT_OUTPUT_FILE_0}" 2>&1

Solution 3:[3]

I had the same issue when building the IOS app.

Open a terminal and type:

  1. git clone https://github.com/nvm-sh/nvm.git ~/.nvm
  2. source ~/.nvm/nvm.sh
  3. nvm alias default system

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Adam Siwiec
Solution 2 Taylor Kline
Solution 3 Biclops