react-native 运行、构建报错

889 阅读4分钟

1. find_spec_for_exe': can't find gem cocoapods (>= 0.a) with executable pod (Gem::GemNotFoundException)

pod --version

/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems.rb:283:in find_spec_for_exe': can't find gem cocoapods (>= 0.a) with executable pod (Gem::GemNotFoundException) from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems.rb:302:in activate_bin_path' from /usr/local/bin/pod:23:in `

'

解决方案

出现这样的错误时,说明 pod 可能没有安装,怎么判断 pod 有没有安装:

brew list cocoapods | grep bin/pod

Warning: Treating cocoapods as a formula. For the cask, use homebrew/cask/cocoapods or specify the --cask flag. To silence this message, use the --formula flag. /opt/homebrew/Cellar/cocoapods/1.16.2_1/bin/pod /opt/homebrew/Cellar/cocoapods/1.16.2_1/libexec/bin/pod /opt/homebrew/Cellar/cocoapods/1.16.2_1/libexec/gems/cocoapods-1.16.2/bin/pod

如果此时这个地方的确输出的有内容,那么是因为路径不对导致的,我们可以看到 /usr/local/bin/pod:23 这个错误,说明是这里的 pod 是不对的,那么我们重新建立符号链接。

# 删除旧的符号链接******
sudo rm /usr/local/bin/pod

# 创建新的符号链接到正确的位置******
sudo ln -sf /opt/homebrew/Cellar/cocoapods/1.16.2_1/bin/pod /usr/local/bin/pod

如果的确是没有安装 pod ,那么可以通过下面的方式进行安装:

brew install cocoapods

2. unable to initiate PIF transfer session (operation in progress?)

Build service could not create build operation: unknown error while handling message: MsgHandlingError(message: "unable to initiate PIF transfer session (operation in progress?)")

出现这个原因一般是因为你的xcode一直打开着,然后在这个过程中你重新安装了 pod-install 导致的,这里的重新安装是指你删除了缓存,然后所有的重新安装。

解决方案

关闭 xcode ,然后重新打开即可。

3. No template named 'function' in namespace 'std'

会出现下面类似的错误。

/Volumes/PortableSSD/Works/seeed-app/apps/sensecraft/ios/Pods/Headers/Private/Flipper/FlipperTransportTypes.h:24:14: No template named 'function' in namespace 'std'

/Volumes/PortableSSD/Works/seeed-app/apps/sensecraft/ios/Pods/FlipperKit/iOS/FlipperKit/FlipperPlatformWebSocket.mm:58:46: Called object type 'facebook::flipper::SocketCertificateProvider' (aka 'int') is not a function or function pointer

/Volumes/PortableSSD/Works/seeed-app/apps/sensecraft/ios/Pods/FlipperKit/iOS/FlipperKit/FlipperPlatformWebSocket.mm:157:32: Called object type 'facebook::flipper::SocketEventHandler' (aka 'int') is not a function or function pointer

解决方案

github.com/facebook/re…

4. No type named 'terminate_handler' in namespace 'std'

Sentry 如果出现这样的错误,那么就需要升级 sentry 的版本。

解决方案

github.com/getsentry/s…

5. /usr/local/bin/node: No such file or directory

/Volumes/PortableSSD/Works/sensecap-hotspot-app/ios/Pods/../../node_modules/react-native/React/FBReactNativeSpec/../../scripts/react_native_pods_utils/script_phases.sh: line 83: /usr/local/bin/node: No such file or directory

解决方案

首先要检查你安装 node 没有,当然我们作为 react-native 开发者, node 肯定是安装了的。你可以先执行 node -v 看看版本,顺便看看安装没有,如果的确安装了,那么就执行 sudo ln -s $(which node) /usr/local/bin/node 来创建软链接。

6. Watchman error: std::__1::system_error: open: /Volumes/PortableSSD/Works/sensecap-hotspot-app: Operation not permitted.

metro-file-map: Watchman crawl failed. Retrying once with node crawler. Usually this happens when watchman isn't running. Create an empty .watchmanconfig file in your project's root folder or initialize a git or hg repository in your project. Error: Watchman error: std::__1::system_error: open: /Volumes/PortableSSD/Works/sensecap-hotspot-app: Operation not permitted. Make sure watchman is running for this project. See facebook.github.io/watchman/do…. node:events:491 throw er; // Unhandled 'error' event ^ Error: std::__1::system_error: open: /Volumes/PortableSSD/Works/sensecap-hotspot-app: Operation not permitted at BunserBuf. (/Volumes/PortableSSD/Works/sensecap-hotspot-app/node_modules/fb-watchman/index.js:99:23) at BunserBuf.emit (node:events:513:28) at BunserBuf.process (/Volumes/PortableSSD/Works/sensecap-hotspot-app/node_modules/bser/index.js:292:10) at /Volumes/PortableSSD/Works/sensecap-hotspot-app/node_modules/bser/index.js:247:12 at process.processTicksAndRejections (node:internal/process/task_queues:85:11) Emitted 'error' event on WatchmanWatcher instance at: at Client. (/Volumes/PortableSSD/Works/sensecap-hotspot-app/node_modules/metro-file-map/src/watchers/WatchmanWatcher.js:114:10) at Client.emit (node:events:513:28) at BunserBuf. (/Volumes/PortableSSD/Works/sensecap-hotspot-app/node_modules/fb-watchman/index.js:111:12) at BunserBuf.emit (node:events:513:28) at /Volumes/PortableSSD/Works/sensecap-hotspot-app/node_modules/bser/index.js:249:12 at process.processTicksAndRejections (node:internal/process/task_queues:85:11) { watchmanResponse: { error: 'std::__1::system_error: open: /Volumes/PortableSSD/Works/sensecap-hotspot-app: Operation not permitted', version: '2024.12.02.00' } }

我的是之前还好好的,但是突然间就出现了这个错误。

解决方案

watchman watch-del-all 
watchman shutdown-server    

7. Verification checksum was incorrect, expected f0397ba6e982c4450f27bf32a2a83292aba035b827a5623a14636ea583318c41, got 79e6d3f986444e5a80afbeccdaf2d1c1cf964baa8d766d20859d653a16c39848

解决方案

github.com/facebook/re…

对于我的项目来说我是这样改的:

diff --git a/node_modules/react-native/third-party-podspecs/boost.podspec b/node_modules/react-native/third-party-podspecs/boost.podspec
index 3950fce..3ae78ba 100644
--- a/node_modules/react-native/third-party-podspecs/boost.podspec
+++ b/node_modules/react-native/third-party-podspecs/boost.podspec
@@ -10,7 +10,7 @@ Pod::Spec.new do |spec|
   spec.homepage = 'http://www.boost.org'
   spec.summary = 'Boost provides free peer-reviewed portable C++ source libraries.'
   spec.authors = 'Rene Rivera'
-  spec.source = { :http => 'https://boostorg.jfrog.io/artifactory/main/release/1.76.0/source/boost_1_76_0.tar.bz2',
+  spec.source = { :http => 'https://archives.boost.io/release/1.76.0/source/boost_1_76_0.tar.bz2',
                   :sha256 => 'f0397ba6e982c4450f27bf32a2a83292aba035b827a5623a14636ea583318c41' }
 
   # Pinning to the same version as React.podspec. 

8 Failed to find a suitable device for the type IBSimDeviceTypeiPad3x (com.apple.dt.Xcode.IBSimDeviceType.iPad-3x) with runtime iOS 18.3 (18.3.1 - 22D8075) - com.apple.CoreSimulator.SimRuntime.iOS-18-3

解决方案

stackoverflow.com/questions/5…

Full Disk Access 可能找不到,只需要在设置中搜索即可:

image.png 然后按照操作把 com.apple.CoreSimulator.CoreSimulatorService.xpc 拖入其中就可以了。