10

I tried building the AwesomeProject app to device. The build succeeds and the splash screen shows, but then I see a red "Could not connect to development server" screen. It says that "Ensure node server is running - run 'npm start' from React root."

It looks like the node server is already running because when I do npm start I get an EADDRINUSE message, saying that the port is already in use.

1
  • I wonder if it has to do with where the app is looking for the server. If this was running in the simulator (which is what it does in the demos), then the server would be localhost. But since this is running on a different device, then 'localhost` would not be the place to look for the server. I see localhost hard-coded in the packager.js script. Commented Mar 28, 2015 at 14:53

5 Answers 5

10

Accessing development server from device You can iterate quickly on device using development server. To do that, your laptop and your phone have to be on the same wifi network.

  1. Open iOS/AppDelegate.m
  2. Change the IP in the URL from localhost to your laptop's IP
  3. In Xcode select your phone as build target and press "Build and run"

ps:http://facebook.github.io/react-native/docs/runningondevice.html#content

Sign up to request clarification or add additional context in comments.

1 Comment

Is there a way to detect the building machine's ip address and use it automatically without having to set it manually each time?
5

Another potential issue (this happened to me): even if you make all of the necessary code changes (cf. http://moduscreate.com/automated-ip-configuration-for-react-native-development/ for a good walkthrough), start the server, etc., it may still fail because of App Transport Security. You'll need to add your IP address to the list of NSExceptionDomains in the app's Info.plist file or, alternatively, disable ATS completely (discouraged--read above article to understand why).

Example entry:

  <key>NSAppTransportSecurity</key>
  <dict>
    <key>NSExceptionDomains</key>
    <dict>
      <key>YOUR-IP-HERE</key>
      <dict>
        <key>NSTemporaryExceptionAllowsInsecureHTTPSLoads</key>
        <false/>
        <key>NSIncludesSubdomains</key>
        <true/>
        <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
        <true/>
        <key>NSTemporaryExceptionMinimumTLSVersion</key>
        <string>1.0</string>
        <key>NSTemporaryExceptionRequiresForwardSecrecy</key>
        <false/>
      </dict>
    </dict>
  </dict>

2 Comments

Doesn't seem to be a solution for me
@jacks205 a solution to what?
2
  1. Take a look in your AppDelegate.m file
  2. Find the 'OPTION 1' and 'OPTION 2' comment blocks. These are located a little after the '@implementation AppDelegate' line.
  3. Make sure that only one of the last lines in the block is uncommented out.
  4. For the option you choose, be sure to follow the instructions on how to load your files.

Also be aware that your computer and phone must be connected to the same wifi network.

According to the commends in AppDelegate.m:

To run on device, change localhost to the IP address of your computer, and make sure your computer and iOS device are on the same Wi-Fi network.

Comments

1

in AppDelegate.m:

To run on device, change localhost to the IP address of your computer, and make sure your computer and iOS device are on the same Wi-Fi network.

I found a related issue on the react-native github issues.

Instruction to run the app without a server: https://github.com/facebook/react-native/issues/240

Comments

-1

This should no longer be an issue. You should be able to follow the docs, which state the following:

  1. Connect your device over usb
  2. Connect your device to the same wifi network as your laptop running Xcode
  3. Click build in run (the "play" button in the upper left) in the Xcode interface with your device selected.

1 Comment

Is still very much an issue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.