React native 从 0.70.5 升级到 0.72.6 出错

React native upgrade from 0.70.5 to 0.72.6 gone wrong

提问人:amit 提问时间:11/17/2023 最后编辑:amit 更新时间:11/22/2023 访问量:125

问:

赏金将在 3 天后到期。这个问题的答案有资格获得 +100 声望赏金。阿米特正在寻找一个有信誉的来源的答案

我正在为我的 React Native 应用程序使用 ignite 样板,并且被迫将 react-native 从 0.70.5 升级到 0.72.6,因为我升级到了 Xcode 15(不知道更好)。现在,在终于成功构建之后,我遇到了一个奇怪的错误。

Unhandled JS Exception: Value is an object, expected an Object
Error: Value is an object, expected an Object

我尝试了,然后在 https://react-native-community.github.io/upgrade-helper/?from=0.70.5&to=0.72.6 的帮助下进行了相关更改,以成功让应用程序在 Xcode 中构建。但噩梦并没有就此结束。npx react-native upgrade

错误没有堆栈跟踪,Xcode 日志如下所示:

enter image description here

这是我在模拟器上看到的:

enter image description here

有什么想法可以调试这个吗?我已经浪费了 2 天。我是 RN 和 Xcode 的新手。

编辑:如果我在模拟器中单击错误底部表上的“重新加载”,则应用程序会在调试器中暂停:

enter image description here

AppDelegate.mm

#import "AppDelegate.h"
#import "RNBootSplash.h"

#import <React/RCTBundleURLProvider.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  self.moduleName = @"App";
  // You can add your custom initial props in the dictionary below.
  // They will be passed down to the ViewController used by React Native.
  self.initialProps = @{};

  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
#else
  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}

@end

AppDelegate.h

#import <RCTAppDelegate.h>
#import <UIKit/UIKit.h>

@interface AppDelegate : RCTAppDelegate

@end
iOS Xcode 反应原生

评论

0赞 Hugo Gresse 11/19/2023
你能分享你的相关XCode主文件吗?(AppDelegate.mm 等)
0赞 amit 11/20/2023
@HugoGresse添加了文件。
0赞 Daniyal Shaikh 11/20/2023
我认为在升级 xCode 时不必升级 React Native 版本。也许你可以尝试降级?
0赞 Daniyal Shaikh 11/20/2023
另外,它适用于 Android 吗?你试过了吗?
0赞 amit 11/21/2023
我已经更新了 Mac OS,真的不想降级。

答:

0赞 Bv2124 11/21/2023 #1

只需创建一个具有稳定版本的RN应用程序的新版本,然后将您的代码粘贴到那里,然后创建一个与旧版本相同的捆绑ID...注意:只需确保XCODE和ANDROID SIMULATOR上的运行版本即可。最主要的是确保您的代码首先在 Android 中运行,然后再加载到 XCODE !!

评论

0赞 amit 11/22/2023
你能再解释一下吗?我对 xcode 和 react-native 相当陌生,希望能稍微牵手来解决这个问题。
0赞 Vicky Ahuja 11/22/2023
如果到目前为止,现有应用程序是在本机代码中进行最大更改的情况下开发的,这可能是最糟糕的方法。@amit
0赞 Vicky Ahuja 11/22/2023 #2

根据随附的屏幕截图,我可以看到您拥有具有 android 和 ios 目录的 expo 应用程序

因此,要升级世博会应用程序,首先应该进行世博会版本升级,这将根据您最新的世博会版本升级所有项目依赖项。

按照以下步骤升级 expo 和 react native 版本,然后使用 react native upgrade helper。

  • 安装新版本的 Expo 软件包:

    npm install expo@^49.0.0 or yarn add expo@^49.0.0
    
  • 升级所有依赖项以匹配 SDK 49(这也将更新 react native 版本):

    npx expo install --fix
    
  • 如果您有 ios 目录,请运行 npx pod-install

  • 应用 React Native Upgrade Helper 中的任何相关更改。

有关更多详细信息,请查看世博博客官方链接中的“升级您的应用程序”部分