React Native执行react-native-git-upgrade报错,无法生成iOS文件夹
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.
Option 1: Use Expo Eject to Regenerate iOS Files (Recommended)
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: Baretemplate. 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.
Option 2: Manually Create & Link an iOS Project
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:
- Open Xcode, create a new "Single View App" with the same name as your React Native project, and save it in an
iosfolder at your project root. - Run
react-native linkin your project root to link any native dependencies you might have. - 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.xcodeprojand add it. - Go to
Build Phases > Link Binary With Librariesand addlibReact.a.
- Right-click your project in Xcode >
- Configure header paths in Xcode's
Build Settings:- Find
Header Search Pathsand add$(SRCROOT)/../node_modules/react-native/React, then check the "recursive" box.
- Find
- Update your iOS project's
AppDelegate.mto 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 - 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 YourProjectNameto 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 originalpackage.jsonto the new project. - Run
npm installto set up dependencies, thenreact-native run-iosto 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_modulesandpackage-lock.json, then runnpm installagain to reset dependencies.
内容的提问来源于stack exchange,提问作者Mizlul

