M1芯片MacBook Air中npx react-native start及run-ios执行失败问题求助
Hey there, let's break down why your React Native iOS setup is failing and fix it without jumping straight to reinstalling Xcode—most likely it's a combination of CocoaPods dependency issues and M1-specific architecture quirks, not a broken Xcode install.
First: The Root Cause of Your Initial Error
That "Failed to install CocoaPods dependencies" message isn't a false alarm—even though you saw the run instructions, your iOS project didn't get the required native dependencies installed. The Ruby interpreter error points to a common M1 Mac issue where the system Ruby or CocoaPods version isn't compatible with Apple Silicon.
Step 1: Fix Ruby & CocoaPods for M1
M1 Macs have compatibility issues with the default system Ruby. Let's get a working Ruby version and reinstall CocoaPods properly:
- Install a Ruby version manager like
rbenv(if you don't have it already):brew install rbenv rbenv install 2.7.6 # This version is stable for CocoaPods rbenv global 2.7.6 - Reinstall CocoaPods targeting the correct architecture (for M1, we need to either use Rosetta or specify the arch):
- Option 1: Open Terminal via Rosetta (right-click Terminal in Launchpad → Get Info → check "Open using Rosetta"), then run:
sudo gem install cocoapods - Option 2: Run the command directly with x86_64 arch in a regular Terminal:
arch -x86_64 sudo gem install cocoapods
- Option 1: Open Terminal via Rosetta (right-click Terminal in Launchpad → Get Info → check "Open using Rosetta"), then run:
- Navigate to your project's iOS directory and reinstall pods:
Wait for this to finish—if it runs without errors, your dependency issue is fixed.cd /Users/boscotsin/Documents/react/test4/ios pod deintegrate pod install
Step 2: Fix npx react-native run-ios Build Failures
Now let's get the iOS build working:
- First, make sure Xcode is set up correctly:
- Open Xcode at least once, accept the license agreement, and let it install any additional components it asks for.
- Verify Command Line Tools are installed: Run
xcode-select --installin Terminal (it will say "already installed" if you're good).
- Run the iOS build with architecture compatibility for M1:
This forces the build to use x86_64 architecture, which avoids arm64 compatibility issues with some older native dependencies.cd /Users/boscotsin/Documents/react/test4 npx react-native run-ios --arch x86_64 - Alternatively, open the
test4/ios/test4.xcworkspacefile in Xcode, select a simulator (like iPhone 14), and click the run button. If there are build errors here, Xcode will show detailed logs—look for issues like missing dependencies or architecture mismatches.
Step 3: Fix npx react-native start "No apps connected" Warning
This warning is just a side effect of the app not being successfully built and running in the simulator. Once you get the app running via run-ios or Xcode, the Metro server will automatically connect to it. If you start the Metro server first, just keep it running, then launch the app—they'll connect once the app loads.
Should You Reinstall Xcode?
Probably not. Xcode issues are rare here—your problem is almost certainly related to CocoaPods/Ruby compatibility on M1. Only consider reinstalling Xcode if all the above steps fail and you see Xcode-specific errors (like corrupted components).
内容的提问来源于stack exchange,提问作者Bosco Tsin

