react-native运行 node错误

主要错误:Node found at: /opt/homebrew/Cellar/node/23.3.0/bin/node

Node found at: /opt/homebrew/Cellar/node/23.3.0/bin/node
/Users/tuling/Library/Developer/Xcode/DerivedData/appIosTemplate-dhjafswddavxexhgawcvgzcoedql/Build/Intermediates.noindex/Pods.build/Debug-iphoneos/hermes-engine.build/Script-46EB2E000379E0.sh: line 9: /opt/homebrew/Cellar/node/23.3.0/bin/node: No such file or directory
Command PhaseScriptExecution failed with a nonzero exit code
导致原因:
这是因为某个阶段(通常是 pod install 后)Hermes 的构建脚本被写死了这个路径。这通常发生于:
    1.  react-native 在安装 Hermes 的 pod 时使用了当前系统中 which node 查到的 node 路径,并写进了构建脚本。
    2.  如果那时你的 node 是安装在 /opt/homebrew/Cellar/... 中,那么路径就会被写死进去,即使后来你切换或卸载了该 node 版本。
解决办法:
1. 创建缺失目录

先创建需要的路径:
sudo mkdir -p /opt/homebrew/Cellar/node/23.3.0/bin

2. 再创建软链接

把你当前实际的 node 路径软链接进去:
sudo ln -s /opt/homebrew/bin/node /opt/homebrew/Cellar/node/23.3.0/bin/node

这样就可以让 Xcode 构建过程中引用到的 “旧路径 node” 实际链接到你当前安装的 Node,从而避免报错。
此方法是个「应急补丁」,但非常有效。
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容