问题
这个问题发生在旧的RN版本(0.57,0.58(<0.58.4),…)和Xcode 10.3中,其中可用模拟器的名称得到了一些调整 在文件node_modules/@react native community/cli/build/commands/runIOS/findMatchingSimulator.js中,react native尝试通过简单的.startsWith检查选择正确的模拟器。由于重命名,检查现在应该使用.includes(ref)
Found Xcode project appupdateDemo.xcodeproj
Could not find iPhone X simulator
Error: Could not find iPhone X simulator
at resolve (/Users/topbrids/rn_share_pro/appupdateDemo/node_modules/react-native/local-cli/runIOS/runIOS.js:149:13)
at new Promise (<anonymous>)
at runOnSimulator (/Users/topbrids/rn_share_pro/appupdateDemo/node_modules/react-native/local-cli/runIOS/runIOS.js:134:10)
at Object.runIOS [as func] (/Users/topbrids/rn_share_pro/appupdateDemo/node_modules/react-native/local-cli/runIOS/runIOS.js:106:12)
at Promise.resolve.then (/Users/topbrids/rn_share_pro/appupdateDemo/node_modules/react-native/local-cli/cliEntry.js:117:22)
解决方案
- 跟新你的RN版本到0.58.4 +
- 如果您无法或不会升级到新的RN版本,则可以使用以下命令自动调整findMatchingSimulator.js文件:
sed -i '' 's/startsWith/includes/g' node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
用这个命令就不用我们去node_modules下面手动修改源码了
还可以把这个命令 放到package.json 的 script节点下面 指定命令 然后用npm run xx 直接执行这个命令 这样用起来更方便一些
{
"name": "appupdateDemo",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest",
"fixOldRnVersion": "sed -i '' 's/startsWith/includes/g' node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js"
},
"dependencies": {
"react": "16.6.1",
"react-native": "0.57.7",
"rn-app-upgrade": "^1.0.4"
},
"devDependencies": {
"babel-jest": "24.9.0",
"jest": "24.9.0",
"metro-react-native-babel-preset": "0.57.0",
"react-test-renderer": "16.6.1"
},
"jest": {
"preset": "react-native"
}
}
[topbrids@topdeMacBook-Pro appupdateDemo]$ npm run fixOldRnVersion
> appupdateDemo@0.0.1 fixOldRnVersion /Users/topbrids/rn_share_pro/appupdateDemo
> sed -i '' 's/startsWith/includes/g' node_modules/react-native/local-cli/runIOS/findMatchingSimulator.js
内容来源于网络如有侵权请私信删除
文章来源: 博客园
- 还没有人评论,欢迎说说您的想法!