React Native空项目在Mac上运行失败,构建报错求助
新建React Native项目Mac运行失败问题
新建React Native项目后,在Mac上尝试运行时失败,已强制卸载并重装Node 3-4次仍未解决。构建过程中出现以下警告与错误:
warning: Run script build phase 'Bundle React Native code and images' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'hermes-engine' from project 'Pods') warning: Run script build phase 'Bundle React Native code and images' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'demo' from project 'demo') warning: Run script build phase '[CP-User] [RN]Check rncore' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'React-Fabric' from project 'Pods') --- xcodebuild: WARNING: Using the first of multiple matching destinations: { platform:iOS Simulator, id:48DE8EFA-7939-4AFC-9EA0-28F59C2AF10D, OS:17.4, name:iPhone 12 min ios 17.4 } { platform:iOS Simulator, id:48DE8EFA-7939-4AFC-9EA0-28F59C2AF10D, OS:17.4, name:iPhone 12 min ios 17.4 } ** BUILD FAILED ** The following build commands failed: PhaseScriptExecution [CP-User]\ Generate\ Specs /Users/atharvasonawane/Library/Developer/Xcode/DerivedData/demo-gemuwpfsyomrgccujyopmbzckjal/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/React-Codegen.build/Script-46EB2E00012A80.sh (in target 'React-Codegen' from project 'Pods') (1 failure)
解决步骤
- 清理Xcode派生数据:打开终端,执行
rm -rf ~/Library/Developer/Xcode/DerivedData/demo-gemuwpfsyomrgccujyopmbzckjal(替换为你项目对应的DerivedData文件夹名),也可直接在Xcode中通过File > Project Settings > Derived Data打开文件夹删除全部内容 - 重新安装CocoaPods:进入项目的ios目录,依次执行
pod deintegrate、rm Podfile.lock、pod install,确保Pod依赖完全重建 - 检查React-Codegen脚本权限:打开Xcode项目,导航到
Pods > Targets > React-Codegen > Build Phases > [CP-User] Generate Specs,确认脚本内容完整,同时在终端执行chmod +x /Users/atharvasonawane/Library/Developer/Xcode/DerivedData/demo-gemuwpfsyomrgccujyopmbzckjal/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/React-Codegen.build/Script-46EB2E00012A80.sh赋予脚本执行权限 - 匹配Node与RN版本:确认使用的Node版本符合React Native官方要求(比如RN 0.73+推荐Node 18.x),可通过
nvm use 18切换版本,避免版本不兼容 - 重置项目依赖:回到项目根目录,执行
rm -rf node_modules package-lock.json,然后npm install重新安装所有Node依赖 - 处理构建脚本警告(可选):针对那些"Run script build phase"警告,可在对应target的Build Phases中找到Run Script步骤,取消勾选"Based on dependency analysis",消除警告干扰
内容的提问来源于stack exchange,提问作者athu070
相关产品推荐
相关产品推荐

