当我运行一个react-native项目时,我得到一个错误,没有bundle URL,但我不知道我做了什么错误,我很困惑。
当前回答
当您不允许通过localhost进行不安全连接时,或者您试图通过http接受不安全连接时,就会发生此问题。
要解决这个问题,在info.plist上添加这个:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSAllowsArbitraryLoadsInWebContent</key>
<true/>
<key>NSAllowsLocalNetworking</key>
<true/>
</dict>
其他回答
在我的情况下,我不小心从Xcode的构建阶段删除了这个脚本。
所以,一定要有这个脚本。如果没有,只需点击“+”&选择“新建运行脚本阶段”,然后粘贴以下代码。
export NODE_BINARY=node
../node_modules/react-native/scripts/react-native-xcode.sh
对于我的用例,我必须删除node_modules目录并运行npm install。
$ rm -rf node_modules (make sure you're in the ios project directory)
$ npm install
如果你得到错误“dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.58。Dylib”,执行以下操作:
$ brew uninstall --force node --ignore-dependencies node
$ brew uninstall icu4c --ignore-dependencies icu4c
$ brew install icu4c
$ brew unlink icu4c && brew link icu4c --force
$ brew install node
$ npm install
首先关闭模拟器,然后在终端上运行这些程序
npm install
react-native run-ios
假设你正在使用nvm并且安装了多个版本的node,下面是解决方案:
假设你在节点v6.9.5中运行npm install -g react-native-cli。 现在运行nvm alias default 6.9.5将节点v6.9.5设为默认值 现在运行react-native run-ios
问题是,你通过nvm安装了多个版本的node,为了安装react-native-cli,你已经切换或安装了最新版本的node,它还没有被标记为nvm中的默认节点。当你运行react-native run-ios时,会打开另一个新的终端窗口,其中默认的nvm不会指向你安装react-native-cli的节点版本。只要遵循上面的设置,我希望能有所帮助。
解决错误No bundle URL present by:
在你的项目根目录中运行以下命令删除iOS构建目录,并在重新构建之前杀死其他React Native会话(假设它们运行在默认端口8081上):
Rm -rf ios/build/;Kill $(lsof -t:8081);react-native run-ios
更新你的React Native工作流,通过将上述命令组合成一个别名,并将其附加到你的Bash配置文件.bashrc,以避免这些错误发生:
Echo "alias rni=\"kill \$(lsof -t -i:8081);Rm -rf ios/build/;React-native run-ios\"" >> ~/.bashrc;源~ / . bashrc
现在你可以用一个简单的别名快捷方式运行React Native iOS构建(不用担心出现一些常见的红色死亡错误屏幕):
rni
推荐文章
- 如何删除默认的导航栏空间在SwiftUI导航视图
- 如何配置历史记录?
- 在react native中隐藏/显示组件
- 如何在iOS中使用Swift编程segue
- Swift -整数转换为小时/分钟/秒
- Swift:声明一个空字典
- React钩子:从回调中访问最新状态
- 在成功提交我的应用程序后,“太多符号文件”
- 首先添加一个UIView,甚至是导航栏
- 我如何改变UIButton标题颜色?
- 在Swift中如何调用GCD主线程上的参数方法?
- NSLayoutConstraints是可动画的吗?
- iOS -构建失败,CocoaPods无法找到头文件
- React-Native:应用程序未注册错误
- 禁用react native按钮