使用React Native开发iOS的时候,报错如下
bash
Pods.build/Debug-iphoneos/hermes-engine.build/Script-46EB2E00021FE0.sh: line 9: /opt/homebrew/Cellar/node/22.2.0/bin/node: No such file or directory
Command PhaseScriptExecution failed with a nonzero exit code
进入Pods.build/Debug-iphoneos/hermes-engine.build/Script-46EB2E00021FE0.sh
查看,发现是使用了NODE_BINARY
来指向node
bash
#!/bin/sh
. "$REACT_NATIVE_PATH/scripts/xcode/with-environment.sh"
CONFIG="Release"
if echo $GCC_PREPROCESSOR_DEFINITIONS | grep -q "DEBUG=1"; then
CONFIG="Debug"
fi
"$NODE_BINARY" "$REACT_NATIVE_PATH/sdks/hermes-engine/utils/replace_hermes_version.js" -c "$CONFIG" -r "0.73.5" -p "$PODS_ROOT"
而iOS的node版本配置是在.xcode.env文件中
bash
# This `.xcode.env` file is versioned and is used to source the environment
# used when running script phases inside Xcode.
# To customize your local environment, you can create an `.xcode.env.local`
# file that is not versioned.
# NODE_BINARY variable contains the PATH to the node executable.
#
# Customize the NODE_BINARY variable here.
# For example, to use nvm with brew, add the following line
# . "$(brew --prefix nvm)/nvm.sh" --no-use
export NODE_BINARY=$(command -v node)
运行的时候,会动态读取node的版本,但是如果升级了node版本,需要将.xcode.env.local
文件删除后重新运行pod install
bash
// .xcode.env.local文件
export NODE_BINARY=/opt/homebrew/Cellar/node/22.2.0/bin/node