You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native执行react-native-git-upgrade报错,无法生成iOS文件夹

Fixing iOS Folder Generation for Detached CRNA React Native Projects

Hey there, let's work through how to get your iOS project set up for that React Native app you started with CRNA. I know dealing with detached projects across Windows/macOS can be tricky, so here are the most reliable fixes—since react-native-git-upgrade is actually deprecated now, that's why you're hitting errors with it.

Since your project started as a CRNA app (built on Expo), even after detaching, Expo's tools can still help you fill in the missing iOS files. Just make sure you're doing this on a macOS machine (iOS development requires Mac):

  • First, update Expo CLI to the latest version: npm install -g expo-cli
  • Navigate to your project root and run: expo eject
  • When prompted, select the React Native: Bare template. This will regenerate both Android and iOS folders, and migrate your existing CRNA configuration to the native project structure. It's the smoothest path since it preserves your existing code and dependencies.

If you'd rather avoid Expo tools entirely, you can build an iOS project from scratch and link it to your existing React Native code:

  1. Open Xcode, create a new "Single View App" with the same name as your React Native project, and save it in an ios folder at your project root.
  2. Run react-native link in your project root to link any native dependencies you might have.
  3. Add React Native's core library to your Xcode project:
    • Right-click your project in Xcode > Add Files to "[Your Project Name]"
    • Navigate to node_modules/react-native/Libraries/React.xcodeproj and add it.
    • Go to Build Phases > Link Binary With Libraries and add libReact.a.
  4. Configure header paths in Xcode's Build Settings:
    • Find Header Search Paths and add $(SRCROOT)/../node_modules/react-native/React, then check the "recursive" box.
  5. Update your iOS project's AppDelegate.m to point to your React Native entry file:
    #import <React/RCTRootView.h>
    
    @implementation AppDelegate
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
      NSURL *jsCodeLocation;
    
      jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
    
      RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                          moduleName:@"YourProjectName"
                                                   initialProperties:nil
                                                       launchOptions:launchOptions];
      rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
    
      self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
      UIViewController *rootViewController = [UIViewController new];
      rootViewController.view = rootView;
      self.window.rootViewController = rootViewController;
      [self.window makeKeyAndVisible];
      return YES;
    }
    
    @end
    
  6. Test it out with react-native run-ios—it should load your existing React Native code.

Option 3: Start Fresh with react-native init & Migrate Code

If the above options hit snags, creating a new React Native project and migrating your code is a solid fallback:

  • On macOS, run react-native init YourProjectName to create a clean, fully configured project with both iOS and Android folders.
  • Copy over your core code (like App.js, src/ folder), assets, and all dependencies from your original package.json to the new project.
  • Run npm install to set up dependencies, then react-native run-ios to verify everything works.

Quick Notes to Avoid Headaches

  • You must use macOS: iOS compilation and Xcode tools only work on Mac—no way around this.
  • Backup first: Always make a copy of your project before making major changes like ejecting or linking native code.
  • Fix dependency conflicts: If you run into errors after installing packages, delete node_modules and package-lock.json, then run npm install again to reset dependencies.

内容的提问来源于stack exchange,提问作者Mizlul

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 08:27:43