【问题标题】:How can i solve: "RCTBridge required dispatch_sync to load" in React Native using yarn workspaces?我该如何解决:使用纱线工作区在 React Native 中“加载 RCTBridge 需要 dispatch_sync 加载”?
【发布时间】:2021-07-09 14:38:28
【问题描述】:

我关注了中篇文章:React Native 0.63 Monorepo walkthrough,以使纱线工作区与 react-native 一起使用。 Everhtings 可以工作,我可以构建我的 iOS 和 Android 应用程序,Metro Bundler 也可以工作,但是当我使用 yarn workspace mobile ios 构建我的 iOS 应用程序时,我从 Metro Bundler 收到以下警告

RCTBridge required dispatch_sync to load RCTDevLoadingView. This may lead to deadlocks

除非我将 react-native 与 yarn 工作区一起使用,否则我不会收到此警告。因此,我怀疑该错误是由我的 monorepo 设置产生的。

您知道如何删除此警告吗?

【问题讨论】:

    标签: react-native yarn-workspaces metro-bundler


    【解决方案1】:

    打开你的/ios/YourAppName/AppDelegate.m

    #import "AppDelegate.h"
    
    // ADD THIS
    #if RCT_DEV
    #import <React/RCTDevLoadingView.h>
    #endif
    // TILL HERE
    
    #import <React/RCTBridge.h>
    #import <React/RCTBundleURLProvider.h>
    #import <React/RCTRootView.h>
    ...
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    
    ...
      RCTBridge *bridge = [[RCTBridge alloc] initWithBundleURL:jsCodeLocation
                                                moduleProvider:nil
                                                 launchOptions:launchOptions];
    // THIS CONDITION
    #if RCT_DEV
      [bridge moduleForClass:[RCTDevLoadingView class]];
    #endif
      RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
                                                       moduleName:@"Test"
                                                initialProperties:nil];
    // TILL HERE
      ...
    }
    

    来源here

    【讨论】:

    • 解决了我的问题。
    • 让它成为选定的答案@Niklas
    【解决方案2】:

    重新打开终端并再次构建应用后,警告不再出现

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-10
      • 2018-02-09
      • 1970-01-01
      • 2021-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-13
      相关资源
      最近更新 更多