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
相关推荐
jump_jump1 分钟前
Ripple:一个现代的响应式 UI 框架
前端·javascript·前端框架
用户904706683579 分钟前
Nuxt css 如何写?
前端
夏天想10 分钟前
element-plus的输入数字组件el-input-number 显示了 加减按钮(+ -) 和 小三角箭头(上下箭头),怎么去掉+,-或者箭头
前端·javascript·vue.js
0思必得011 分钟前
[Web自动化] Selenium基础介绍
前端·python·selenium·自动化·web自动化
Filotimo_13 分钟前
前端.d.ts文件作用
前端
进击的野人14 分钟前
Vue 3 响应式数据解构:toRef 与 toRefs 的深度解析
前端·vue.js·前端框架
ohyeah15 分钟前
CSS 作用域隔离实战:React、Vue 与 Styled Components 的三种范式
前端
二哈喇子!31 分钟前
前端HTML、CSS、JS、VUE 汇总
开发语言·前端
小白路过31 分钟前
node-sass和sass兼容性使用
前端·rust·sass
IT_陈寒31 分钟前
Python 3.12 新特性实战:这5个改进让我的开发效率提升40%
前端·人工智能·后端