main.jsbundle文件显示在我的iOS项目中,但仍抛出"No bundle URL present"(不存在捆绑包网址) [英] main.jsbundle file showing in my iOS project but still throwing "No bundle url present"
问题描述
我正在创建一个新的React Native应用,但遇到诸如不存在捆绑包URL"之类的错误.在iOS Simulator上运行时.
I am creating a new React Native app but facing errors like "No bundle URL present" while running it on iOS Simulator.
在iOS上运行App的命令:
Command to Run App on iOS:
react-native run-ios --port=8089
我尝试了以下链接中建议的所有可能的解决方案.
I tried every possible solution suggested on the below links.
https: //www.andrewcbancroft.com/2017/04/22/solving-react-natives-no-bundle-url-present-error/
还有很多其他参考文献,但根本没有运气.
and lots of other references but no luck at all.
解决方案1:我试图在info.plist中添加AppTranportSecurity标志.
Solution 1: I tried to add AppTranportSecurity flags in info.plist.
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSAllowsArbitraryLoadsInWebContent</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>localhost</key>
<dict>
<key>NSAllowsLocalNetworking</key>
<true/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>
解决方案2:尝试从iOS文件夹中删除构建,然后重新构建.
Solution 2: Try to remove the build form the iOS folder and build it again.
- 使用
rm -r build
删除构建文件夹
- 再次运行
react-native run-ios
- Remove the build folder with
rm -r build
- Run
react-native run-ios
again
解决方案3:在 Package.json 文件中的以下行中添加了
Solution 3: Added below line in Package.json file
"build:ios": "react-native bundle --entry-file ./index.js --platform ios --bundle-output ios/main.jsbundle"
根本没有运气.
即使我的Metro Builder在MacFee防火墙应用使用的 8081 上运行在端口8089 上.
Even my metro builder running on port 8089 as 8081 uses by MacFee firewall app.
推荐答案
最后,我解决了上述问题.以下是可帮助我解决此问题的解决方案.
Finally, I resolved the above issue. Below is the solution which helps me to resolve this issue.
因此,正如我在问题中提到的那样,我尝试了在SO或其他门户网站上发布的所有大多数解决方案,但均未成功.因此,我对生成的iOS代码进行了更多研究,并了解了以下几点.
So As I mentioned in my question I tried all most every solution posted on SO or other portal but didn't succeed. So I investigate more on generated iOS code and come to know the below points.
- 我的main.jsbundle生成了该文件,但是没有JS代码,所以这是我在此应用程序中遇到的第一个问题.
解决方案:尝试使用以下react-native命令生成main.jsbundle文件,并在iOS文件夹中进行验证.
Solution: Try to generate your main.jsbundle file with the below react-native command and verify it in your iOS folder.
react-native bundle --entry-file='index.js' --bundle-output='./ios/main.jsbundle' --dev=false --platform='ios' --assets-dest='./ios'
或
react-native bundle --entry-file index.js --platform ios --dev false --bundle-output ios/main.jsbundle --assets-dest ios
队列:它将做什么?
并且::它将使用所有JS代码手动生成main.jsbundle文件.
And: It will manually generate main.jsbundle file with all JS code.
- 生成.jsbundle文件后,我尝试再次运行该应用程序,并收到相同的错误"No bundle url"
解决方案::我发现手动生成的文件未添加到我的Project目标中,所以我将main.jsbundle文件添加到了我的应用目标中.
Solution: I found that manually generated file is not added in my Project target so I added main.jsbundle file into my app target.
第1步:在XCode-> Project Navigator窗格中选择main.jsbundle
Step1: Select Your main.jsbundle in XCode -> Project Navigator pane
第二步:在目标成员资格"部分中检查相关的项目目标.
Step2: Check Related Project Target in Target Membership section.
最后也是最后一步是在package.json中添加iOS的构建脚本命令
And last and final step is to add build script command for iOS in package.json
"scripts": {
...
"bundle:ios": "react-native bundle --entry-file index.js --platform ios --dev false --bundle-output ios/main.jsbundle --assets-dest ios",
"postinstall": "npm run bundle:ios"
}
希望这将帮助那些在此问题上苦苦挣扎的人.
Hope this will helps who struggle with this issue.
从字面上来看,最近三天我都在为这个问题而苦苦挣扎.
I literally struggle with this issue form the last 3 days.
感谢StackOverflow& Github问题.
Thanks to StackOverflow & Github issues.
参考链接: https://github.com/facebook/react-native/Issues/18472
这篇关于main.jsbundle文件显示在我的iOS项目中,但仍抛出"No bundle URL present"(不存在捆绑包网址)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!