ios react-native 中“不存在捆绑 URL”是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42610070/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 08:58:15  来源:igfitidea点击:

What is the meaning of 'No bundle URL present' in react-native?

iosreactjsreact-native

提问by Yingch Xue

When I run a react-native project, I get a error no bundle URL present, but I don't know what mistakes I do, I was very confused.

当我运行一个 react-native 项目时,我得到一个错误no bundle URL present,但我不知道我犯了什么错误,我很困惑。

enter image description here

在此处输入图片说明

回答by Luke Schoen

Solve the error No bundle URL presentby:

No bundle URL present通过以下方式解决错误:

  • Running the following command in your project root directory to delete the iOS build directory, and to kill other React Native sessions (assuming they're running on default port 8081) before re-building:
  • 在您的项目根目录中运行以下命令以删除 iOS 构建目录,并在重新构建之前终止其他 React Native 会话(假设它们在默认端口 8081 上运行):

rm -rf ios/build/; kill $(lsof -t -i:8081); react-native run-ios

rm -rf ios/build/; kill $(lsof -t -i:8081); react-native run-ios

  • Update your React Native workflow to avoid these error occur by combining the above combination of commands into an alias and appending it to your Bash config file .bashrc with this command:
  • 更新你的 React Native 工作流程以避免这些错误发生,方法是将上述命令组合组合成一个别名,并使用以下命令将其附加到你的 Bash 配置文件 .bashrc 中:

echo "alias rni=\"kill \$(lsof -t -i:8081); rm -rf ios/build/; react-native run-ios\"" >> ~/.bashrc; source ~/.bashrc

echo "alias rni=\"kill \$(lsof -t -i:8081); rm -rf ios/build/; react-native run-ios\"" >> ~/.bashrc; source ~/.bashrc

Now you can run React Native iOS build (without worrying about some of the common red error screens of death appearing) with a simple alias shortcut:

现在您可以使用简单的别名快捷方式运行 React Native iOS 构建(无需担心出现一些常见的红色错误屏幕):

rni

rni

回答by Skip Suva

I just ran into this problem as well (first time getting started with React Native). The problem disappeared when - while an ios simulation(react-native run-ios) was running - I ran npm installand then react-native run-iosagain. In the terminal window, it showed that it was bundling, and then the simulator showed the welcome screen.

我也遇到了这个问题(第一次开始使用 React Native)。问题就消失了时-而在iOS模拟(react-native run-ios)正在运行-我跑npm install,然后react-native run-ios一次。在终端窗口中显示正在捆绑,然后模拟器显示欢迎屏幕。

Check this link for briefsafter react-native init PropertyFinderline try to use npm start(This one works for me)

react-native init PropertyFinder尝试使用后,请检查此链接以获取摘要npm start(这个对我有用)

========================================================================

================================================== ======================

UPDATE for 16.9

16.9 更新

My port 8081 was blocked by McAfee. Using a different port directly wasn't working react-native start --port=8082and react-native run-ios --port=8082

我的端口 8081 被 McAfee 阻止了。使用不同的端口直接不工作react-native start --port=8082react-native run-ios --port=8082

Tried almost all solutions given here. but anything didn't work.

尝试了这里给出的几乎所有解决方案。但没有任何效果。

        "react": "16.9.0",
        "react-dom": "^16.12.0",
        "react-native": "0.61.5",

Solution:

解决方案:

Searched for 8081 in Xcode and replaced all of them with 8082. Then run the same commands to build and run the app. App works smoothly

在 Xcode 中搜索 8081 并将它们全部替换为 8082。然后运行相同的命令来构建和运行应用程序。应用程序运行流畅

react-native start --port=8082
react-native run-ios --port=8082

enter image description here

在此处输入图片说明

回答by parse

Had same problem when I did bundle my app. Check that your main.jsbundleis targeted to your main Project

当我捆绑我的应用程序时遇到了同样的问题。检查您main.jsbundle的目标是否针对您的主要项目

回答by cwRichardKim

As instructed in the error message:

按照错误消息中的说明:

Agreeing to the Xcode/iOS license requires admin privileges, please run "sudo xcodebuild -license" and then retry this command.

同意 Xcode/iOS 许可证需要管理员权限,请运行“sudo xcodebuild -license”,然后重试此命令。

Running the following command worked:

运行以下命令有效:

sudo xcodebuild -license

回答by Mateo Marconi

Close your simulator and the terminal. Open new one and go to your project, then upgrade your react-native like this:

关闭模拟器和终端。打开新的并转到您的项目,然后像这样升级您的 react-native:

react-native upgrade

Issue in: Infinite recursion in RCTFatal when the bundle fails to execute.

问题:当包执行失败时,RCTFalal中的无限递归

回答by Witalo Benicio

This problem happens when you not allow unsecure connections via localhost, or maybe you tried to accept unsecure connections via http.

当您不允许通过 localhost 进行不安全的连接,或者您试图通过 http 接受不安全的连接时,就会发生此问题。

To fix this, add this on info.plist:

要解决此问题,请将其添加到info.plist

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
        <key>NSAllowsArbitraryLoadsInWebContent</key>
        <true/>
        <key>NSAllowsLocalNetworking</key>
        <true/>
    </dict>
</key>

回答by Khoa

Reason:

原因:

This is because the app cannot find out the server (which serves the UI - by javascript code).

这是因为应用程序无法找到服务器(为 UI 提供服务 - 通过 javascript 代码)。

Solution:

解决方案:

  • Make sure everything related to react native closed (not necessary, just to have clean start for my solution, after my explanation, you can figure out this is needed or not)
  • run npm run startor yarn startfirst
  • wait for this command done job (usually you will see Loading dependency graph, done.)
  • run react-native run-ios/android
  • 确保与本机反应相关的所有内容都关闭(不是必需的,只是为了让我的解决方案有一个干净的开始,经过我的解释,您可以确定是否需要这样做)
  • 运行npm run startyarn start首先
  • 等待这个命令完成工作(通常你会看到Loading dependency graph, done.
  • react-native run-ios/android

Explanation:

解释:

  • React Native comes with 2 parts:

    • Native part
    • Javascript part
  • Build commands:

    • react-native run-ios/androidis to build native part then deploy to devices and start app on devices (simulator/emulator/real device). This usually took 3~4 mins to finish.

    • npm run startor yarn startis to build the javascript part and start the dev server to serve the built UI to the app. This usually took 30 secs to finish.

  • React Native 有两部分:

    • 原生部分
    • Javascript 部分
  • 构建命令:

    • react-native run-ios/android是构建本机部分,然后部署到设备并在设备(模拟器/模拟器/真实设备)上启动应用程序。这通常需要 3~4 分钟才能完成。

    • npm run start或者yarn start是构建 javascript 部分并启动开发服务器以将构建的 UI 提供给应用程序。这通常需要 30 秒才能完成。

=> Normally, the javascript part finished first then the native part came later. (based on time they used).

=> 通常,javascript 部分先完成,然后本地部分出现。(基于他们使用的时间)。

=> this is only true for the first time build (fresh build).

=> 这仅适用于第一次构建(新构建)。

=> for re-build:

=> 用于重新构建:

  • The native part just took 10~15 secs to check changes and because no change for native part => done before the javascript part was built and served. (I am not sure the javascript part was rebuilt or not but it took long time than native part)

  • So that is why we had this issue, the app ran and required thing that did not exist yet.

  • 原生部分只需要 10~15 秒来检查更改,因为在构建和提供 javascript 部分之前,原生部分没有更改 => 完成。(我不确定 javascript 部分是否重建,但它比原生部分花费了很长时间)

  • 所以这就是我们遇到这个问题的原因,应用程序运行并需要尚不存在的东西。

Bonus:

奖金:

  • react-native run-ios/androidwill auto start the dev server for you.
  • That's why when you ran react-native run-ios/androidright after react-native init <app_name>, everything ran well. (because auto start feature and the time was took for fresh build as state above).
  • Other "removing" solutions worked because they forced rebuilding.
  • react-native run-ios/android将为您自动启动开发服务器。
  • 这就是为什么当你紧随react-native run-ios/android其后时react-native init <app_name>,一切都运行良好。(因为自动启动功能和新构建的时间如上所述)。
  • 其他“删除”解决方案之所以有效,是因为它们强制重建。

Time used on this answer was relative to my machine => may different on others.

这个答案所用的时间与我的机器有关 => 其他机器可能会有所不同。

回答by Kusal Kithmal

Try running this code:

尝试运行此代码:

$ sudo xcodebuild -license

$ sudo xcodebuild -license

This may fix the issue. This works for me.

这可能会解决问题。这对我有用。

回答by sonlexqt

I had the same error and was able to run the app only through Xcode. react-native run-iosdid not work. To resolve the issue you need to remove the buildfolder at YOUR_PROJECT/ios/build/. After this you should be able to run your app through react-native run-iosagain. Hope this helps.

我遇到了同样的错误,只能通过 Xcode 运行该应用程序。react-native run-ios不工作。要解决此问题,您需要删除位于 的build文件夹YOUR_PROJECT/ios/build/。在此之后,您应该能够react-native run-ios再次运行您的应用程序。希望这可以帮助。

回答by Vivek

Most of the cases this problem occurs when the DNS lookup / IP lookup fails to find localhost.

大多数情况下,当 DNS 查找/IP 查找无法找到 localhost 时,会出现此问题。

Solution :

解决方案 :

Try adding the localhost ip to your etc host file.

尝试将 localhost ip 添加到您的 etc 主机文件中。

you can add the below lines to your etc host file (/etc/hosts)

您可以将以下几行添加到您的 etc 主机文件 (/etc/hosts)

127.0.0.1 localhost

127.0.0.1 本地主机

255.255.255.255 broadcasthost

255.255.255.255 广播主机

::1 l . ocalhost

::1升。本地主机

To confirm this is the issueyou can hit the bundle url on safari (if you try it in chrome this will resolve but safari won't be able to resolve it). http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false

要确认这是问题,您可以点击 safari 上的 bundle url(如果您在 chrome 中尝试,这将解决,但 safari 将无法解决)。http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false