mDNS fails to initialize: 'Object is not a constructor' error with bonjour-service #3987

Closed
opened 2026-02-16 17:42:11 -05:00 by yindo · 0 comments
Owner

Originally created by @Jkker on GitHub (Dec 29, 2025).

Originally assigned to: @adamdotdevin on GitHub.

Description

When running opencode web --mdns, mDNS service discovery fails to initialize due to a bundling issue with the bonjour-service library.

Error

From the logs (~/.local/share/opencode/log/*.log):

ERROR 2025-12-30T04:15:55 +8ms service=mdns error=Object is not a constructor (evaluating 'new import_bonjour_service.default') mDNS publish failed

Observed Behavior

  • opencode web --mdns starts and displays:
    Local access:        http://localhost:4096
    Network access:      http://192.168.1.1:4096
    mDNS:                opencode.local
    
  • However, no UDP socket is bound on port 5353 - the mDNS service is not actually advertising
  • Querying opencode.local via mDNS returns no response

Expected Behavior

  • mDNS should advertise opencode.local so devices on the local network can discover the service

Root Cause

The error Object is not a constructor (evaluating 'new import_bonjour_service.default') indicates a CommonJS/ESM interop issue in the bundled binary. The bonjour-service module is not being imported correctly.

Looking at the binary strings:

// ../../node_modules/.bun/bonjour-service@1.3.0/node_modules/bonjour-service/dist/lib/mdns-server.js

The bundler (Bun) appears to have issues with the default export from bonjour-service.

Environment

  • opencode version: 1.0.208
  • Platform: Linux (WSL2 with mirrored networking)
  • Installation: via mise

Reproduction

  1. Run opencode web --mdns
  2. Check logs for the error
  3. Verify no UDP 5353 socket is bound: ss -ulnp | grep 5353
  4. Attempt to resolve: avahi-resolve -n opencode.local (fails)

Suggested Fix

The import of bonjour-service likely needs adjustment for proper ESM/CJS interop. Something like:

// Instead of:
import Bonjour from 'bonjour-service'
new Bonjour()

// May need:
import * as BonjourModule from 'bonjour-service'
const Bonjour = BonjourModule.default || BonjourModule
new Bonjour()

Or ensure the bundler is configured to handle this module's exports correctly.

Originally created by @Jkker on GitHub (Dec 29, 2025). Originally assigned to: @adamdotdevin on GitHub. ## Description When running `opencode web --mdns`, mDNS service discovery fails to initialize due to a bundling issue with the `bonjour-service` library. ## Error From the logs (`~/.local/share/opencode/log/*.log`): ``` ERROR 2025-12-30T04:15:55 +8ms service=mdns error=Object is not a constructor (evaluating 'new import_bonjour_service.default') mDNS publish failed ``` ## Observed Behavior - `opencode web --mdns` starts and displays: ``` Local access: http://localhost:4096 Network access: http://192.168.1.1:4096 mDNS: opencode.local ``` - However, **no UDP socket is bound on port 5353** - the mDNS service is not actually advertising - Querying `opencode.local` via mDNS returns no response ## Expected Behavior - mDNS should advertise `opencode.local` so devices on the local network can discover the service ## Root Cause The error `Object is not a constructor (evaluating 'new import_bonjour_service.default')` indicates a CommonJS/ESM interop issue in the bundled binary. The `bonjour-service` module is not being imported correctly. Looking at the binary strings: ``` // ../../node_modules/.bun/bonjour-service@1.3.0/node_modules/bonjour-service/dist/lib/mdns-server.js ``` The bundler (Bun) appears to have issues with the default export from `bonjour-service`. ## Environment - opencode version: 1.0.208 - Platform: Linux (WSL2 with mirrored networking) - Installation: via mise ## Reproduction 1. Run `opencode web --mdns` 2. Check logs for the error 3. Verify no UDP 5353 socket is bound: `ss -ulnp | grep 5353` 4. Attempt to resolve: `avahi-resolve -n opencode.local` (fails) ## Suggested Fix The import of `bonjour-service` likely needs adjustment for proper ESM/CJS interop. Something like: ```typescript // Instead of: import Bonjour from 'bonjour-service' new Bonjour() // May need: import * as BonjourModule from 'bonjour-service' const Bonjour = BonjourModule.default || BonjourModule new Bonjour() ``` Or ensure the bundler is configured to handle this module's exports correctly.
yindo added the web label 2026-02-16 17:42:11 -05:00
yindo closed this issue 2026-02-16 17:42:11 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#3987