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

M1芯片MacBook Air中npx react-native start及run-ios执行失败问题求助

Troubleshooting React Native iOS Setup on M1 MacBook Air

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
      
  • Navigate to your project's iOS directory and reinstall pods:
    cd /Users/boscotsin/Documents/react/test4/ios
    pod deintegrate
    pod install
    
    Wait for this to finish—if it runs without errors, your dependency issue is fixed.

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 --install in Terminal (it will say "already installed" if you're good).
  • Run the iOS build with architecture compatibility for M1:
    cd /Users/boscotsin/Documents/react/test4
    npx react-native run-ios --arch x86_64
    
    This forces the build to use x86_64 architecture, which avoids arm64 compatibility issues with some older native dependencies.
  • Alternatively, open the test4/ios/test4.xcworkspace file 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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.29 20:02:33