{"id":13894,"library":"react-native-zeroconf","title":"React Native Zeroconf Discovery","description":"react-native-zeroconf is a comprehensive utility library that enables React Native applications to discover and publish network services using Zeroconf protocols like Bonjour and mDNS. The current stable version is 0.14.0, which was released approximately 3 months ago. It appears to follow an active, though not strictly scheduled, release cadence, with updates addressing platform compatibility, including Android 15+ requirements. It offers cross-platform support for both iOS and Android, providing developers with robust service discovery and publishing capabilities. A key differentiator is its dual Android implementation, allowing selection between the native NSD (Network Service Discovery) API or an embedded DNSSD (mDNSResponder) for potentially broader compatibility. Its active development ensures ongoing support for evolving mobile OS requirements, such as the upcoming Android 15+ page size alignment.","status":"active","version":"0.14.0","language":"javascript","source_language":"en","source_url":"git://github.com/Apercu/react-native-zeroconf","tags":["javascript","react-component","react-native","zeroconf","bonjour","avahi","network","lan","ios"],"install":[{"cmd":"npm install react-native-zeroconf","lang":"bash","label":"npm"},{"cmd":"yarn add react-native-zeroconf","lang":"bash","label":"yarn"},{"cmd":"pnpm add react-native-zeroconf","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency for a React Native module, providing the native bridge.","package":"react-native","optional":false}],"imports":[{"note":"While CommonJS `require` might work in some React Native environments, modern React Native (especially with Hermes) and TypeScript projects primarily use ES module `import` syntax. The library exports a default class.","wrong":"const Zeroconf = require('react-native-zeroconf')","symbol":"Zeroconf","correct":"import Zeroconf from 'react-native-zeroconf'"},{"note":"The library extends EventEmitter and uses `on` for event subscription, not `addListener` which is also a valid EventEmitter method but `on` is more commonly documented for this library's usage.","wrong":"zeroconf.addListener('resolved', service => { /* ... */ })","symbol":"Zeroconf events","correct":"zeroconf.on('resolved', service => { /* ... */ })"}],"quickstart":{"code":"import Zeroconf from 'react-native-zeroconf'\nimport { useEffect } from 'react';\n\nconst ZeroconfScanner = () => {\n  useEffect(() => {\n    const zeroconf = new Zeroconf()\n\n    zeroconf.on('resolved', service => {\n      console.log('Found service:', service.name)\n      console.log('IP addresses:', service.addresses)\n      console.log('Port:', service.port)\n      console.log('Service details:', service)\n    })\n\n    zeroconf.on('start', () => console.log('Scan started'))\n    zeroconf.on('stop', () => console.log('Scan stopped'))\n    zeroconf.on('error', error => console.error('Zeroconf error:', error))\n\n    // Start scanning for HTTP services. Consider 'DNSSD' for better Android compatibility.\n    // zeroconf.scan('http', 'tcp', 'local.', 'DNSSD')\n    zeroconf.scan('http', 'tcp', 'local.')\n\n    // Stop scanning after 10 seconds and clean up listeners\n    const timer = setTimeout(() => {\n      zeroconf.stop()\n      console.log('All services after 10s:', zeroconf.getServices())\n      // It's crucial to remove listeners on unmount to prevent memory leaks\n      zeroconf.removeDeviceListeners(); // Specific method for cleanup (not in provided README, but good practice)\n    }, 10000)\n\n    return () => {\n      clearTimeout(timer)\n      zeroconf.stop()\n      zeroconf.removeDeviceListeners(); // Ensure cleanup on component unmount\n    }\n  }, [])\n\n  return null // This component doesn't render anything visible\n}\n\nexport default ZeroconfScanner;\n","lang":"javascript","description":"Demonstrates how to initialize Zeroconf, listen for resolved services, and start/stop scanning for HTTP services. Includes essential cleanup for React components and error handling."},"warnings":[{"fix":"Remove `react-native link` from your installation steps. Autolinking should handle the native module setup automatically. If issues persist, try reinstalling `node_modules` and `pod install` in the `ios` directory.","message":"For React Native versions 0.60 and above, manual linking via `react-native link` is deprecated and can cause build failures due to autolinking. Ensure you remove any manual `link` commands if upgrading an older project or setting up a new one.","severity":"breaking","affected_versions":">=0.60"},{"fix":"Add `NSBonjourServices` array (e.g., `<string>_http._tcp.</string>`) and `NSLocalNetworkUsageDescription` string to your `Info.plist`. For more advanced use cases or consistent discovery, apply for the Multicast Networking Entitlement with Apple.","message":"On iOS 14 and newer, applications must explicitly declare the service types they intend to discover in `Info.plist` using `NSBonjourServices` and provide a `NSLocalNetworkUsageDescription` key. Failure to do so will prevent network discovery and result in an empty list of services. Additionally, for network-intensive operations, you might need to request the Multicast Networking Entitlement through Apple.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Ensure the required `<uses-permission>` tags are present within the `<manifest>` tag of your `AndroidManifest.xml`.","message":"Essential network permissions (`INTERNET`, `ACCESS_NETWORK_STATE`, `ACCESS_WIFI_STATE`, `CHANGE_WIFI_MULTICAST_STATE`) must be explicitly declared in your `AndroidManifest.xml`. Without these, Zeroconf discovery will fail silently or with permission denied errors on Android.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Upgrade to `react-native-zeroconf@0.14.0` or newer to ensure compatibility with Android 15+ and Google Play requirements.","message":"Starting November 1, 2025, Google Play requires all apps to be compatible with devices using 16KB page sizes (Android 15+). While `react-native-zeroconf@0.14.0` includes the necessary alignment fix, users on older versions may experience crashes or instability on Android 15+ devices when this requirement becomes active.","severity":"gotcha","affected_versions":"<0.14.0"},{"fix":"If encountering unreliable discovery on Android, explicitly specify `'DNSSD'` as the `implType` parameter when calling `scan()`: `zeroconf.scan('http', 'tcp', 'local.', 'DNSSD')`.","message":"On Android, the library offers two implementations for service discovery: the native `NSD` (default) and an embedded `DNSSD`. `DNSSD` is often recommended for better cross-device compatibility, especially if `NSD` proves unreliable or inconsistent on specific Android versions or OEM devices, a common issue with Android's NSD.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Test on a physical Android device or configure your Android emulator for multicast support, which usually involves advanced networking setup (e.g., using TAP networking with QEMU).","message":"Zeroconf discovery relies on multicast networking which is often unsupported by Android emulators by default. For reliable testing, a physical Android device on the same network as the services is recommended.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Always stop the Zeroconf scan and remove listeners when the component unmounts or the app goes into the background. Use React Native's `AppState` API to manage scans based on app foreground/background state. Example: `zeroconf.stop(); zeroconf.removeDeviceListeners();`","message":"Leaving scans active indefinitely can lead to memory leaks or unexpected crashes, especially when the app is backgrounded or the device sleeps, particularly on iOS and older Android versions.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"search_vec":"'0.14.0':37 '15':64,129 '3':42 'activ':50,114 'address':59 'ago':44 'align':132 'allow':94 'android':63,76,92,128 'api':103 'appear':46 'applic':18 'approxim':41 'avahi':142 'bonjour':29,141 'broader':111 'cadenc':56 'capabl':85 'compat':61,112 'compon':136 'comprehens':11 'cross':69 'cross-platform':68 'current':33 'develop':78,115 'differenti':88 'discov':20 'discoveri':4,82,102 'dnssd':107 'dual':91 'embed':106 'enabl':15 'ensur':116 'evolv':120 'follow':48 'implement':93 'includ':62 'io':74,145 'javascript':133 'key':87 'lan':144 'librari':13 'like':28 'mdns':31 'mdnsrespond':108 'mobil':121 'month':43 'nativ':2,7,17,98,139 'network':23,100,143 'nsd':99 'offer':67 'ongo':117 'os':122 'page':130 'platform':60,70 'potenti':110 'protocol':27 'provid':77 'publish':22,84 'react':1,6,16,135,138 'react-compon':134 'react-nat':137 'react-native-zeroconf':5 'releas':40,55 'requir':65,123 'robust':80 'schedul':54 'select':95 'servic':24,81,101 'size':131 'stabl':34 'strict':53 'support':71,118 'though':51 'upcom':127 'updat':58 'use':25 'util':12 'version':35 'zeroconf':3,8,26,140","created_at":"2026-04-20T01:56:51.580818+00:00","updated_at":"2026-04-20T01:56:51.580818+00:00","problems":[{"fix":"For React Native 0.60+, ensure autolinking is working by deleting `node_modules` and `Podfile.lock` (iOS), then `npm install` or `yarn install`, followed by `cd ios && pod install` (for iOS/macOS). Avoid using `react-native link`.","cause":"The native module is not correctly linked or multiple linking attempts have occurred, typically due to `react-native link` being used with autolinking on newer React Native versions.","error":"Native module 'RNZeroconf' was not found."},{"fix":"Ensure `import Zeroconf from 'react-native-zeroconf'` is at the top of your file and `const zeroconf = new Zeroconf()` is called before attempting to use its methods. If using Expo, run `npx expo prebuild` to generate native projects or confirm native modules are properly configured.","cause":"The `Zeroconf` instance or its underlying native module is not correctly initialized or the import failed, leading to an `undefined` or `null` reference. This can also happen in Expo managed workflows if not using `expo prebuild`.","error":"TypeError: Cannot read property 'scan' of null"},{"fix":"Verify that `NSBonjourServices` and `NSLocalNetworkUsageDescription` are correctly configured in your `Info.plist`. If the problem persists on iOS 17+, you may need to request the Multicast Networking Entitlement from Apple.","cause":"This error typically indicates an issue with `NSNetService` not being able to resolve or publish services on iOS, often related to missing `Info.plist` entries or network entitlements, especially on iOS 17+.","error":"Error: { NSNetServicesErrorCode = \"-72007\"; NSNetServicesErrorDomain = 10; }"},{"fix":"Double-check Android `AndroidManifest.xml` permissions and iOS `Info.plist` entries (`NSBonjourServices`, `NSLocalNetworkUsageDescription`). Ensure devices are on the same Wi-Fi network. On Android, try explicitly using the `DNSSD` implementation for scanning: `zeroconf.scan('http', 'tcp', 'local.', 'DNSSD')`.","cause":"This is a common issue with several potential causes, including incorrect permissions, services not being on the same network, firewall blocking multicast, or unreliable Android NSD implementation.","error":"No services found / Scan returns empty array / 'resolved' event never fires."},{"fix":"Implement robust lifecycle management: stop Zeroconf scans (`zeroconf.stop()`) and remove listeners (`zeroconf.removeDeviceListeners()`) when the app moves to the background (using React Native's `AppState` API) or when the component unmounts. Re-initialize and restart scans when the app comes to the foreground.","cause":"This generic JavaScript error in React Native often indicates an unhandled exception propagating from native code, frequently observed when Zeroconf scans are active and the app is backgrounded or the device sleeps, leading to network state changes.","error":"Uncaught, unspecified \"error\" event. (-72000)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/Apercu/react-native-zeroconf","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/react-native-zeroconf","openapi_spec":null,"status_page":null,"smithery":null,"categories":["http-networking"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}