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

react-native run-ios无法启动应用但Xcode构建正常的问题求助

Hey there! Let’s troubleshoot why react-native run-ios isn’t launching your app properly even though building via Xcode works perfectly. I’ve dealt with this exact issue a few times, so here are targeted steps to fix it:

Troubleshooting react-native run-ios App Launch & Bundle Build Issues

1. Manually Start the Metro Bundler

Often, the automatic bundler launch fails silently with the run-ios command. Try this:

  • Kill any lingering Node processes first: run killall node in your terminal.
  • Start the bundler manually with cache reset: npx react-native start --reset-cache. Wait until you see the message "Loading dependency graph, done."
  • Open a second terminal window and re-run react-native run-ios while the bundler is running.

2. Fix React Native CLI Configuration

Outdated or misconfigured CLI can break the run-ios workflow:

  • Update the global React Native CLI: npm install -g @react-native-community/cli
  • For project-local CLI (recommended for newer RN versions), verify it’s installed: npm list @react-native-community/cli. If missing or outdated, reinstall it: npm install @react-native-community/cli --save-dev

3. Explicitly Target Your App’s Scheme

The CLI might be using the wrong build scheme, even if Xcode picks the right one:

  • Run react-native run-ios --scheme [YourAppName] (replace [YourAppName] with your actual project scheme name — it’s usually the same as your project folder name).
  • Double-check the "Bundle React Native code and images" script in Xcode’s Build Phases:
    1. Open your project in Xcode, go to your target’s Build Phases tab
    2. Ensure the script looks exactly like this (adjust the path if your node_modules is in a different location):
      export NODE_BINARY=node
      ../node_modules/react-native/scripts/react-native-xcode.sh
      

4. Wipe Corrupted Build Artifacts

Stale build files are a common culprit here:

  • Clean Xcode’s build folder: In Xcode, go to Product > Clean Build Folder (or press Shift + Command + K)
  • Reset all React Native caches and dependencies:
    npx react-native clean
    npm install
    cd ios && pod install && cd ..
    
  • Delete Xcode’s DerivedData manually: Navigate to ~/Library/Developer/Xcode/DerivedData, find the folder for your project, and delete it.

5. Reset or Switch Simulators

Sometimes the simulator’s state is messed up:

  • Erase the simulator’s content: Open the simulator, go to Device > Erase All Content and Settings, then try react-native run-ios again.
  • Test with a different simulator: Run react-native run-ios --simulator "iPhone 15" (use any simulator you have installed) to rule out issues with your default simulator.

6. Verify Terminal Environment & Xcode Tools

Ensure your terminal has access to the correct Xcode setup:

  • Check Xcode command line tools path: xcode-select --print-path. It should point to /Applications/Xcode.app/Contents/Developer. If not, run xcode-select --switch /Applications/Xcode.app/Contents/Developer.
  • Make sure you’ve accepted Xcode’s license agreement: Run sudo xcodebuild -license accept if you haven’t already.

If none of these steps work, run the command with verbose logging to get more clues: react-native run-ios --verbose. The detailed logs will show exactly where the process is hanging or failing.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 04:25:06