Antonio Labra
Antonio Labra

Reputation: 2000

React native could not connect to development server. iOS 14.4 [react-native]

I don't know what is wrong with my react-native project I wrote "npx react-native run-ios --simulator "myDevice" and I have a red screen with the following messages:

Could not connect to development server.

Ensure the following:

  • Node server is running and available on the same network - run 'npm start' from react-native root
  • Node server URL is correctly set in AppDelegate
  • WiFi is enabled and connected to the same network as the Node Server

URL: http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=org.reactjs.native.example.citas

RCTFatal __28-[RCTCxxBridge handleError:]_block_invoke _dispatch_call_block_and_release _dispatch_client_callout _dispatch_main_queue_callback_4CF CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE __CFRunLoopRun CFRunLoopRunSpecific GSEventRunModal -[UIApplication _run] UIApplicationMain main start 0x0

I changed my URL at info.plist using my current computer's IP but isn't working, I'm very confused about it. How can I connect my node server with react-native?

Thank you so much!

Here you have my settings: Catalina 10.15.4 iOS 14.4 react-native-cli: 2.0.1 react-native: 0.64.2 node: v14.17.0 npm: v6.14.13

PodFile

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, '10.0'

target 'citas' do
  config = use_native_modules!

  use_react_native!(
    :path => config[:reactNativePath],
    # to enable hermes on iOS, change `false` to `true` and then install pods
    :hermes_enabled => false
  )

  target 'citasTests' do
    inherit! :complete
    # Pods for testing
  end

  # Enables Flipper.
  #
  # Note that if you have use_frameworks! enabled, Flipper will not work and
  # you should disable the next line.
  #use_flipper!()

  post_install do |installer|
    react_native_post_install(installer)
  end
end

Info.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>en</string>
    <key>CFBundleDisplayName</key>
    <string>citas</string>
    <key>CFBundleExecutable</key>
    <string>$(EXECUTABLE_NAME)</string>
    <key>CFBundleIdentifier</key>
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>$(PRODUCT_NAME)</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>1.0</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleVersion</key>
    <string>1</string>
    <key>LSRequiresIPhoneOS</key>
    <true/>
    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
        <key>NSAllowsArbitraryLoadsInWebContent</key>
        <true/>
        <key>NSAllowsLocalNetworking</key>
        <true/>
        <key>NSExceptionDomains</key>
        <dict>
            <key>jsCodeLocation = [NSURL URLWithString:@&quot;http://192.168.0.19:8081/index.ios.bundle?platform=ios&amp;dev=true&quot;];</key>
            <dict>
                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                <true/>
            </dict>
        </dict>
    </dict>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string></string>
    <key>UILaunchStoryboardName</key>
    <string>LaunchScreen</string>
    <key>UIRequiredDeviceCapabilities</key>
    <array>
        <string>armv7</string>
    </array>
    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UIViewControllerBasedStatusBarAppearance</key>
    <false/>
</dict>
</plist>

  

Upvotes: 1

Views: 8650

Answers (2)

Antonio Labra
Antonio Labra

Reputation: 2000

I'd been stuck per days and the problem was related to Watchman Permissions. See the verified solution and I hope this help someone

Homebrew Permissions for Watchman on Muti-user Mac

Upvotes: 2

Abhishek Kumar
Abhishek Kumar

Reputation: 86

Are you sure you have a simulator named "myDevice"?

Normally, we use the name of the device for example, iPhone 12 Pro

react-native run-ios --simulator="iPhone 12 Pro"

Can you try running this once Also, you do not need to specify the ip address of your local machine, just writing localhost is enough

<dict>
  <key>localhost</key>
    <dict>
      <key>NSExceptionAllowsInsecureHTTPLoads</key>
        <true/>
    </dict>
</dict>

Upvotes: 0

Related Questions