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
相关推荐
geovindu27 分钟前
css: Timeline scribble
前端·css·iphone
沙漠之主9 小时前
C++编程教学设计资料:从入门到实战的完整课程方案
java·前端·c++
hasty9 小时前
不上传新包,也能改变用户拿到的版本:npm dist-tag 的 OIDC 权限治理
前端·npm·node.js
Csvn9 小时前
diff 算法(虚拟 DOM Reconciliation)
前端
前端snow10 小时前
ai agent --- 文件存储
前端
Frag0ut10 小时前
Chrome四大版本获取及共存指南:Stable/Beta/Dev/Canary
前端·chrome·浏览器·dev·beta·canary·共存版
IT_陈寒12 小时前
SpringBoot自动配置坑了我一把,原来是这样绕过去的
前端·人工智能·后端
广州华水科技12 小时前
单北斗GNSS变形监测在大坝安全监测中的应用与优势
前端
zeng不错12 小时前
B站 173 个投稿活动看到眼瞎?我写了个扩展,主打一个精准打击
前端
Latchh12 小时前
前端导出的JPEG红字发糊,质量要拉到100才清楚
前端·图像处理·人工智能·计算机视觉