首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在iOS中运行默认RN本机项目会出现错误

在iOS中运行默认RN本机项目会出现错误
EN

Stack Overflow用户
提问于 2022-02-19 14:14:53
回答 3查看 3.6K关注 0票数 10

知道出什么问题了吗?我已经更新了所有相关组件的最新版本。

我正在创建一个默认的react本机项目,并试图运行iOS模拟器。

代码语言:javascript
运行
复制
npx react-native init {project_name}
cd {project_name}
npx react-native run-ios    

我收到以下错误:

代码语言:javascript
运行
复制
/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

所讨论的脚本(自生成)如下:

代码语言:javascript
运行
复制
#!/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

试图从Xcode运行时会产生相同的错误。

不用说,我试着跑

代码语言:javascript
运行
复制
nvm install default

并收到以下错误:

代码语言:javascript
运行
复制
Version 'default' not found - try `nvm ls-remote` to browse available versions.
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2022-02-26 00:26:10

我不经常回答Stackoverflow的问题,但我也遇到了同样的问题,并使用this post来解决这个问题。

它基本上围绕着命令

代码语言:javascript
运行
复制
nvm alias default system

或者将system转换为您想要的任何版本的NodeJS。

票数 25
EN

Stack Overflow用户

发布于 2022-05-11 11:04:54

在构建IOS应用程序时,我也遇到了同样的问题。

打开终端并键入:

~/.nvm/nvm.sh

  • nvm
  1. git克隆https://github.com/nvm-sh/nvm.git ~/..nvm
  2. 别名默认系统
票数 4
EN

Stack Overflow用户

发布于 2022-05-27 16:07:00

与其修改系统node,不如将the commit that removes the find-node.sh script与修补程序包一起应用,解决了我们团队中遇到此问题的开发人员的这个问题。

我们补丁的内容很简单

代码语言:javascript
运行
复制
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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71185785

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档