最近原來的老項目有點問題需要處理一下,運行啟動命令,就報了如下錯誤,提示找不到iPhone 6 模擬器。
react-native run-ios
Owaiss-Mac:pdm owaisahmed$ react-native run-ios
Found Xcode project pdm.xcodeproj
Could not find iPhone 6 simulator
Error: Could not find iPhone 6 simulator
at resolve (/Users/fantuan/Documents/react-native-projects/pdm/node_modules/react-native/local-cli/runIOS/runIOS.js:149:13)
at new Promise (<anonymous>)
at runOnSimulator (/Users/fantuan/Documents/react-native-projects/pdm/node_modules/react-native/local-cli/runIOS/runIOS.js:134:10)
at Object.runIOS [as func] (/Users/fantuan/Documents/react-native-projects/pdm/node_modules/react-native/local-cli/runIOS/runIOS.js:106:12)
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,使用如下命令可以查看當前項目的具體環境信息:
React Native Environment Info:
System:
OS: macOS 10.14.6
CPU: (8) x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
Memory: 26.40 MB / 16.00 GB
Shell: 5.3 - /bin/zsh
Binaries:
Node: 10.14.1 - ~/.nvm/versions/node/v10.14.1/bin/node
Yarn: 1.13.0 - ~/.nvm/versions/node/v10.14.1/bin/yarn
npm: 6.4.1 - ~/.nvm/versions/node/v10.14.1/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.4, macOS 10.14, tvOS 12.4, watchOS 5.3
Android SDK:
API Levels: 23, 25, 26, 27, 28, 29
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
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
IDEs:
Android Studio: 3.1 AI-173.4720617
Xcode: 10.3/10G8 - /usr/bin/xcodebuild
npmPackages:
react: 16.5.0 => 16.5.0
react-native: 0.57.0 => 0.57.0
npmGlobalPackages:
react-native-cli: 2.0.1
react-native-create-library: 3.1.2
經過一番查閱資料發現是Xcode的版本升級到10導致的。
解決方案如下:
1.打開項目node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js文件
2.修改文件的第31行
if (!version.startsWith('iOS') && !version.startsWith('tvOS')) {
continue;
}
為如下代碼
if (!version.startsWith('com.apple.CoreSimulator.SimRuntime.iOS')
&& !version.startsWith('com.apple.CoreSimulator.SimRuntime.tvOS')) {
continue;
}
吐血注意:
對於ReactNative項目開發中,請不要輕易升級Xcode等編譯,除非你十分精通。
歡迎大家關注我的公眾號:君偉說,定期推送開發技術。