NodeJS 响应本机iOS阶段脚本执行[CP用户]\生成\规格构建错误

jm81lzqq  于 2022-12-12  发布在  Node.js
关注(0)|答案(1)|浏览(131)

我一直在与这个错误斗争,它发生在一个星期前,当我切换到新的机器.下面是我的机器配置-〉节点,npm,Yarn等:

node --version -> v16.18.1
which node -> /opt/homebrew/opt/node@16/bin/node
which npm -> /opt/homebrew/opt/node@16/bin/npm
which yarn -> /opt/homebrew/bin/yarn

我也安装了nvm。这会不会是因为yarn没有指向节点安装的位置而发生的?因为目录不同。
然后,我尝试使用npm uninstall -g yarn卸载yarn,并使用npm install -g yarn重新安装它,然后进入我的项目,删除节点模块,重新安装pod和所有内容,但这个错误仍然存在。
我经历了这些解决方案,没有一个真正适合我-〉PhaseScriptExecution [CP-User] error in React Native
下面是我得到的构建错误:

/bin/sh -c /Users/username/Library/Developer/Xcode/DerivedData/project-bqzfnxmekpsgkmfaztyrfllaudqg/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/FBReactNativeSpec.build/Script-46EB2E00047A70.sh
Node found at: /opt/homebrew/Cellar/node/19.0.1/bin/node

/Users/username/Desktop/project/ios/Pods/../../node_modules/react-native/React/FBReactNativeSpec/../../scripts/react_native_pods_utils/script_phases.sh: line 83: /opt/homebrew/Cellar/node/19.0.1/bin/node: No such file or directory
Command PhaseScriptExecution failed with a nonzero exit code

** BUILD FAILED **

The following build commands failed:
    PhaseScriptExecution [CP-User]\ Generate\ Specs /Users/username/Library/Developer/Xcode/DerivedData/project-bqzfnxmekpsgkmfaztyrfllaudqg/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/FBReactNativeSpec.build/Script-46EB2E00047A70.sh (in target 'FBReactNativeSpec' from project 'Pods')
(1 failure)

/.zshrc:-

export JAVA_HOME=/Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home
export PATH="/opt/homebrew/bin:$PATH"
export ANDROID_SDK_ROOT=$HOME/Library/Android/sdk
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_SDK_ROOT/emulator
export PATH=$PATH:$ANDROID_SDK_ROOT/platform-tools
export PATH=$PATH:$ANDROID_SDK_ROOT/cmdline-tools/latest/bin
export PATH=$PATH:$ANDROID_SDK_ROOT/ndk/21.4.7075529
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
export PATH="/opt/homebrew/opt/node@16/bin:$PATH"

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"

正如我所说的,当我在我的项目文件夹中执行yarn install时,由于yarn没有指向节点安装目录,它可能考虑了错误的版本,并使用错误的版本下载,因此出现了此错误...
有人能帮我解决这个问题吗?
提前感谢!

编辑-1

这是我的node_modules/react-native/scripts/下的find-node-for-xcode.sh

#!/bin/bash
# Copyright (c) Meta Platforms, Inc. and 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

# WHY WE NEED THIS:
# This script is used to find a valid instance of `node` installed in the machine.
# This script is sourced by other scripts to get access to node.
# Specifically, it is used by the `react-native-xcode.sh` script, invoked by a
# post-build phase in Xcode, to build the js files required by React Native.
#
# DEPRECATION NOTE:
# React Native should not make assumptions on your current node environment.
# This file is deprecated and will be removed in a future release in favor of something
# node-agnostic and configurable by the developers.

# 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

# Set up volta if present
if [[ -x "$HOME/.volta/bin/node" ]]; then
  export VOLTA_HOME="$HOME/.volta"
  export PATH="$VOLTA_HOME/bin:$PATH"
fi

# Set up the fnm node version manager if present
if [[ -x "$HOME/.fnm/fnm" ]]; then
  eval "$("$HOME/.fnm/fnm" env)"
elif [[ -x "$(command -v brew)" && -x "$(brew --prefix fnm)/bin/fnm" ]]; then
  eval "$("$(brew --prefix fnm)/bin/fnm" env)"
fi
0s0u357o

0s0u357o1#

我有同样的错误在我的机器上,看起来像是与nvm有关。我通过修补React Native修复了它。这里是我的修补程序。

diff --git a/node_modules/react-native/scripts/find-node.sh b/node_modules/react-native/scripts/find-node.sh
index 5d6d2c4..ceabb9e 100755
--- a/node_modules/react-native/scripts/find-node.sh
+++ b/node_modules/react-native/scripts/find-node.sh
@@ -4,7 +4,7 @@
 # This source code is licensed under the MIT license found in the
 # LICENSE file in the root directory of this source tree.
 
-set -e
+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

您可以使用https://github.com/ds300/patch-package来应用它或手动更改它。

相关问题