React Native iOS报Node版本错误

使用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
相关推荐
new code Boy21 分钟前
escape谨慎使用
前端·javascript·vue.js
叠叠乐39 分钟前
robot_state_publisher 参数
java·前端·算法
Kiri霧39 分钟前
Range循环和切片
前端·后端·学习·golang
小张快跑。1 小时前
【Java企业级开发】(十一)企业级Web应用程序Servlet框架的使用(上)
java·前端·servlet
小白阿龙1 小时前
Flex布局子元素无法垂直居中
前端
秋田君1 小时前
前端工程化部署入门:Windows + Nginx 实现多项目独立托管与跨域解决方案
前端·windows·nginx
江城开朗的豌豆2 小时前
阿里邮件下载器使用说明
前端
半兽先生2 小时前
Web 项目地图选型指南:从 Leaflet 到 MapTalks,如何选择合适的地图引擎?
前端
hssfscv2 小时前
Javaweb 学习笔记——html+css
前端·笔记·学习