最近原来的老项目有点问题需要处理一下,运行启动命令,就报了如下错误,提示找不到iPhone 6 模拟器。
1react-native run-ios 2 3Owaiss-Mac:pdm owaisahmed$ react-native run-ios 4Found Xcode project pdm.xcodeproj 5 6Could not find iPhone 6 simulator 7 8Error: Could not find iPhone 6 simulator 9 at resolve (/Users/fantuan/Documents/react-native-projects/pdm/node_modules/react-native/local-cli/runIOS/runIOS.js:149:13) 10 at new Promise (<anonymous>) 11 at runOnSimulator (/Users/fantuan/Documents/react-native-projects/pdm/node_modules/react-native/local-cli/runIOS/runIOS.js:134:10) 12 at Object.runIOS [as func] (/Users/fantuan/Documents/react-native-projects/pdm/node_modules/react-native/local-cli/runIOS/runIOS.js:106:12) 13 at Promise.resolve.then (/Users/fantuan/Documents/react-native-projects/pdm/node_modules/react-native/local-cli/cliEntry.js:117:22)
老项目是一年前的当时项目的的版本时还是0.57,期间工作电脑的系统版本升级到了10.14.6, XCode的版本也升级到了10.3,使用如下命令可以查看当前项目的具体环境信息:
1React Native Environment Info: 2 System: 3 OS: macOS 10.14.6 4 CPU: (8) x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz 5 Memory: 26.40 MB / 16.00 GB 6 Shell: 5.3 - /bin/zsh 7 Binaries: 8 Node: 10.14.1 - ~/.nvm/versions/node/v10.14.1/bin/node 9 Yarn: 1.13.0 - ~/.nvm/versions/node/v10.14.1/bin/yarn 10 npm: 6.4.1 - ~/.nvm/versions/node/v10.14.1/bin/npm 11 Watchman: 4.9.0 - /usr/local/bin/watchman 12 SDKs: 13 iOS SDK: 14 Platforms: iOS 12.4, macOS 10.14, tvOS 12.4, watchOS 5.3 15 Android SDK: 16 API Levels: 23, 25, 26, 27, 28, 29 17 Build Tools: 23.0.1, 23.0.3, 25.0.2, 25.0.3, 26.0.3, 27.0.3, 28.0.0, 28.0.2, 28.0.3, 29.0.2 18 System Images: android-23 | Intel x86 Atom, android-23 | Intel x86 Atom_64, android-23 | Google APIs Intel x86 Atom_64, android-29 | Google APIs Intel x86 Atom 19 IDEs: 20 Android Studio: 3.1 AI-173.4720617 21 Xcode: 10.3/10G8 - /usr/bin/xcodebuild 22 npmPackages: 23 react: 16.5.0 => 16.5.0 24 react-native: 0.57.0 => 0.57.0 25 npmGlobalPackages: 26 react-native-cli: 2.0.1 27 react-native-create-library: 3.1.2
经过一番查阅资料发现是Xcode的版本升级到10导致的。 解决方案如下: 1.打开项目node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js文件 2.修改文件的第31行
1if (!version.startsWith('iOS') && !version.startsWith('tvOS')) { 2 continue; 3}
为如下代码
1if (!version.startsWith('com.apple.CoreSimulator.SimRuntime.iOS') 2 && !version.startsWith('com.apple.CoreSimulator.SimRuntime.tvOS')) { 3 continue; 4}
吐血注意: 对于ReactNative项目开发中,请不要轻易升级Xcode等编译,除非你十分精通。
欢迎大家关注我的公众号:君伟说,定期推送开发技术。