react native新建项目踩坑记录
首页 专栏 react-native 文章详情
0

react native新建项目踩坑记录

MangoGoing 发布于 2 月 25 日

问题一:

ios环境下按照官网步骤并且pod已经设置完清华源后启动npm run ios,报错如下:

** BUILD FAILED **


The following build commands failed:
    CompileC /Users/loser/Library/Developer/Xcode/DerivedData/test0205-dasunahpjpavelgmslwgmvjhesxy/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/Flipper.build/Objects-normal/x86_64/FlipperRSocketResponder.o /Users/loser/Documents/projects/test0205/ios/Pods/Flipper/xplat/Flipper/FlipperRSocketResponder.cpp normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)

解决方案

网上大部分的答案全都是类似这种:

1.  cd /ios
2.  run `pod install`
3.  cd ..
4.  delete _build_ folder
5.  run `react-native run-ios`

亲测无效。
正确的解决方案如下:
这是因为iOS项目use_flipper中的use_flipper。

use_flipper! 

因此,我需要使用use_flipper来指示Flipper-Folly版本为

use_flipper!({ 'Flipper-Folly' => '2.3.0' }) 

更改之后,它运行完美。

如果安装pod依赖过程中卡在 boost-for-react-native或其他依赖,请在ios/Podfile文件头加入 pod 'boost-for-react-native', :git => 'https://gitee.com/mirrors/boost-for-react-native.git’,下载gitee中的依赖,另外,控制台需要单独配置代理,你的梯子默认是不对控制台生效的

问题二:

解决以上问题后运行,再次报错,如下:

error: Can’t find ‘node’ binary to build React Native bundle If you have non-standard nodejs installation, select your project in Xcode, find ‘Build Phases’ - ‘Bundle React Native code and images’ and change NODE_BINARY to absolute path to your node executable (you can find it by invoking ‘which node’ in the terminal)

因为我是使用了nvm作为node的版本管理工具,所以xCode在使用node时,找不到。

which node
/Users/sharkship/.nvm/versions/node/v12.16.1/bin/node

我们可以使用软连接的方式,将node链接到 /usr/local/bin/node目录上,xCode即可找到node

ln -s $(which node) /usr/local/bin/node

当然在使用nvm更换完node版本时,需要使用上述命令进行node的更新。

react-native
阅读 26 更新于 2 月 26 日
收藏
分享
本作品系原创, 采用《署名-非商业性使用-禁止演绎 4.0 国际》许可协议
avatar
MangoGoing

没有bug可言

286 声望
148 粉丝
关注作者
0 条评论
得票 时间
提交评论
avatar
MangoGoing

没有bug可言

286 声望
148 粉丝
关注作者
宣传栏
目录

问题一:

ios环境下按照官网步骤并且pod已经设置完清华源后启动npm run ios,报错如下:

** BUILD FAILED **


The following build commands failed:
    CompileC /Users/loser/Library/Developer/Xcode/DerivedData/test0205-dasunahpjpavelgmslwgmvjhesxy/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/Flipper.build/Objects-normal/x86_64/FlipperRSocketResponder.o /Users/loser/Documents/projects/test0205/ios/Pods/Flipper/xplat/Flipper/FlipperRSocketResponder.cpp normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)

解决方案

网上大部分的答案全都是类似这种:

1.  cd /ios
2.  run `pod install`
3.  cd ..
4.  delete _build_ folder
5.  run `react-native run-ios`

亲测无效。
正确的解决方案如下:
这是因为iOS项目use_flipper中的use_flipper。

use_flipper! 

因此,我需要使用use_flipper来指示Flipper-Folly版本为

use_flipper!({ 'Flipper-Folly' => '2.3.0' }) 

更改之后,它运行完美。

如果安装pod依赖过程中卡在 boost-for-react-native或其他依赖,请在ios/Podfile文件头加入 pod 'boost-for-react-native', :git => 'https://gitee.com/mirrors/boost-for-react-native.git’,下载gitee中的依赖,另外,控制台需要单独配置代理,你的梯子默认是不对控制台生效的

问题二:

解决以上问题后运行,再次报错,如下:

error: Can’t find ‘node’ binary to build React Native bundle If you have non-standard nodejs installation, select your project in Xcode, find ‘Build Phases’ - ‘Bundle React Native code and images’ and change NODE_BINARY to absolute path to your node executable (you can find it by invoking ‘which node’ in the terminal)

因为我是使用了nvm作为node的版本管理工具,所以xCode在使用node时,找不到。

which node
/Users/sharkship/.nvm/versions/node/v12.16.1/bin/node

我们可以使用软连接的方式,将node链接到 /usr/local/bin/node目录上,xCode即可找到node

ln -s $(which node) /usr/local/bin/node

当然在使用nvm更换完node版本时,需要使用上述命令进行node的更新。