react-native版本: 0.67
按官方文档初始化并运行项目
$ npx react-native init AwesomeProject
$ yarn ios
错误信息如下
The following build commands failed:
PhaseScriptExecution [CP-User]\ Generate\ Specs /Users/zh/Library/Developer/Xcode/DerivedData/AwesomeProject-cvxgkvyxvvajjvaydcivldmzlgxr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/FBReactNativeSpec.build/Script-5F4C70EF7D90A5A5BDAEB404279F232A.sh (in target 'FBReactNativeSpec' from project 'Pods') (1 failure)
可能的原因
- 项目路径包含了空白字符
- 使用了nvm来进行node安装
我是因为原因2,解决方案为前往node_modules/react-native/scripts/find-node.sh
, 注释掉文件里面的这部分内容
if [[ -s "$HOME/.nvm/nvm.sh" ]]; then
# shellcheck source=/dev/null
. "$HOME/.nvm/nvm.sh"
elif [[ -x "$(command -v brew)" && -s "$(brew --prefix nvm)/nvm.sh" ]]; then
# shellcheck source=/dev/null
. "$(brew --prefix nvm)/nvm.sh"
fi
然后再执行 yarn ios
, 即可执行成功
参考: https://*.com/a/70309731/6048696