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.
Most of the cases this problem occurs when the DNS lookup / IP lookup fails to find localhost.
Solution :
Try adding the localhost ip to your etc host file.
you can add the below lines to your etc host file (/etc/hosts)
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 l . ocalhost
To confirm this is the issue you 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
Try running this code:
$ sudo xcodebuild -license
This may fix the issue. This works for me.
It has happened to me as well, after restarting my mac. There's a launchPackager terminal window opening up when you run your app on the simulator. I closed that window and terminated the process (I also cloosed the simulator), then run again react-native run-ios and everything works fine.
This problem happens when you not allow unsecure connections via localhost, or maybe you tried to accept unsecure connections via http.
To fix this, add this on info.plist
:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSAllowsArbitraryLoadsInWebContent</key>
<true/>
<key>NSAllowsLocalNetworking</key>
<true/>
</dict>
another thing that working for me , is to open the project in xcode, and then clean and build it. usually it reruns the packaging server and solve the problem.
Assuming that you are using nvm
and multiple versions of node installed, here is the solution:
npm install -g react-native-cli
in node v6.9.5
. node v6.9.5
as default by running nvm alias default 6.9.5
react-native run-ios
The problem is, you have multiple versions of node installed via nvm
and to install react-native-cli
you have switched or installed latest version of node, which is not marked as default node to point in nvm
yet. When you run react-native run-ios
this opens up another new terminal window in which default nvm
is not pointed to the node version where you have installed react-native-cli
. Just follow the above setup, I hope that should help.