提问人:amit 提问时间:11/17/2023 最后编辑:amit 更新时间:11/22/2023 访问量:125
React native 从 0.70.5 升级到 0.72.6 出错
React native upgrade from 0.70.5 to 0.72.6 gone wrong
问:
我正在为我的 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 日志如下所示:
这是我在模拟器上看到的:
有什么想法可以调试这个吗?我已经浪费了 2 天。我是 RN 和 Xcode 的新手。
编辑:如果我在模拟器中单击错误底部表上的“重新加载”,则应用程序会在调试器中暂停:
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
答:
只需创建一个具有稳定版本的RN应用程序的新版本,然后将您的代码粘贴到那里,然后创建一个与旧版本相同的捆绑ID...注意:只需确保XCODE和ANDROID SIMULATOR上的运行版本即可。最主要的是确保您的代码首先在 Android 中运行,然后再加载到 XCODE !!
评论
根据随附的屏幕截图,我可以看到您拥有具有 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 中的任何相关更改。
有关更多详细信息,请查看世博博客官方链接中的“升级您的应用程序”部分
评论