Skip to content

desktop: internal browser panel disappears — browser scope fails with SyntaxError: Identifier 'n' has already been declared #60369

Closed

Description

@jonathanvera-sketch

Description

Summary

The desktop app's internal browser backend dies with SyntaxError: Identifier 'n' has already been declared, and the "Browser/Navegador" entry vanishes from the session + panel menu. Restarting the app restores it temporarily, then it disappears again.

Environment

  • opencode version: 2.2.2 (Desktop packaged app; bundled CLI 2.2.2)
  • OS: Windows_NT 10.0.26300 (win32 x64)
  • Terminal: Unavailable: terminal environment variables are not set
  • Shell: C:\WINDOWS\system32\cmd.exe
  • Install/channel: latest (packaged, auto-updater reports 2.2.2 up-to-date)
  • Active plugins: none (opencode.jsonc is {})

Reproduction

  1. Open OpenCode Desktop 2.2.2 on Windows, one window, local v2 server (2.2.2 on http://127.0.0.1:28894).
  2. Open a session and use the internal browser (menu + → Browser, or Ctrl+Alt+B). It works at first — pages load.
  3. After some time, open the + panel menu again: the Browser entry (globe icon) is gone; only Review, Terminal, Open file remain.
  4. App restart brings the entry back, then it disappears again.

Expected Behavior

The Browser panel entry should stay available while connected to a compatible local v2 server.

Actual Behavior

The entry is hidden. main.log shows the browser scope failing:

[error] (main) scope finalizer failed {
  scope: 'browser',
  error: "SyntaxError: Identifier 'n' has already been declared\n" +
    '    at compileSourceTextModule (node:internal/modules/esm/utils:320:16)\n' +
    ...
}

### Plugins

open code

### OpenCode version

2.2.2

### Steps to reproduce

_No response_

### Screenshot

_No response_

### Operating System

WINDOWS 11

### Terminal

WINDOWS TERMINAL

Activity

  1. opencodejr commented on Oct 29, 2026

    @opencodejr
    Contributor

    Thanks for the detailed report and the main.log excerpt. I can confirm the error.

    I built the desktop main process from the v2.2.2 tag (bunx electron-vite build) and checked each output chunk with node --check. The only chunk that fails is the internal browser's pane chunk, with exactly your error: SyntaxError: Identifier 'n' has already been declared.

    The cause seems to be two top-level require declarations in that chunk. One comes from the CommonJS shim banner the desktop build adds to every main chunk. The other comes from a bundled @effect/platform-node module. The minifier renames both to n. The browser plugin loads that chunk lazily and also waits for it when shutting down. That matches the scope finalizer failed { scope: 'browser' } entry in your log.

    A build of the latest dev (b19d143) fails the same way. The script below reproduces it, and I've left details for the maintainers. One thing I couldn't explain: you see the browser working at first, so the menu entry disappearing may also involve the states described in #60023 (Browser launcher disappears until restart).

    Reproduction script (check-pane-chunk.sh)
    #!/usr/bin/env bash
    # Reproduces #60369: the desktop main-process browser "pane" chunk fails to compile as ESM.
    # Usage: check-pane-chunk.sh [git-ref]   (default: v2.2.2). Needs git, bun, node >= 20.
    set -euo pipefail
    REF="${1:-v2.2.2}"
    WT="${TMPDIR:-/tmp}/oc-pane-$REF"
    git clone -q --depth 1 --branch "$REF" https://github.com/anomalyco/opencode.git "$WT" 2>/dev/null \
      || { git clone -q https://github.com/anomalyco/opencode.git "$WT" && git -C "$WT" checkout -q "$REF"; }
    cd "$WT" && bun install >/dev/null
    cd packages/desktop && bunx electron-vite build >/dev/null
    cd out/main
    status=0
    for f in *.js; do
      cp "$f" /tmp/chk.mjs   # .mjs so node parses it as an ES module, as Electron does
      if ! node --check /tmp/chk.mjs 2>/tmp/chk.err >/dev/null; then
        echo "FAIL $f: $(grep -m1 -o 'SyntaxError.*' /tmp/chk.err)"
        status=1
      fi
    done
    # Show the colliding declarations: the CommonJS banner's `require` and
    # @effect/platform-node's internal/http.js top-level `const require = createRequire(...)`.
    grep -o '^.\{0,120\}' pane-*.js | head -1
    exit $status

    Run it: bash check-pane-chunk.sh

  2. miaolong001 commented on Oct 30, 2026

    @miaolong001

    Same failure on macOS, confirming it is build-to-build and not specific to the Windows artifact. Different chunk hash, identical defect.

    Environment

    • opencode: Desktop 2.2.2 (Homebrew cask opencode-desktop 2.2.2, packaged, auto-update reports 2.2.2 as latest)
    • Bundled CLI 2.2.2 is the active server: ~/Library/Application Support/ai.opencode.desktop/cli/2.2.2-arm64/opencode-cli serve --service on 127.0.0.1:49374 (verified with lsof; no separate opencode from PATH involved)
    • OS: macOS 26.6.2 (build 25G83), arm64
    • Node 24.22.1, used only for the offline check below
    • Plugins: none ("plugins": [] in ~/.config/opencode/opencode.json), no browser permission rules anywhere

    Symptoms

    1. Open a session, click + in the side panel: only Review / Terminal / Open file are listed. Browser is never offered, not even briefly.
    2. Ctrl+Cmd+B ("Open browser") does nothing; the command is disabled.
    3. browser.* is absent from the Code Mode tool catalog.
    4. A clean launch never has the pane, so on macOS there is no "works at first, disappears later" stage — that part of the report is likely desktop: Browser launcher disappears from the new tab view until app restart #60023. It has never been available on this machine.

    Quitting and relaunching the app, and separately restarting the sidecar so the app spawns its own bundled CLI, both leave it broken. It is deterministic, not a transient state.

    Decisive test

    Extracted every chunk under /out/main/ from /Applications/OpenCode.app/Contents/Resources/app.asar and compiled each one as an ES module, the way Electron loads them:

    # 650 chunks from /out/main, each copied to .mjs and checked
    $ node --check pane-Bs9c3oLB.js
    SyntaxError: Identifier 'n' has already been declared
        at checkSyntax (node:internal/main/check_syntax:84:5)
    
    650 chunks checked, 1 failed: out/main/pane-Bs9c3oLB.js (84,183 bytes)

    The failing chunk is the browser pane — same file class as pane-CwHDCUMq.js in the Windows reports, different hash. The other 649 chunks compile fine, so this matches the maintainer's analysis (shim banner require + bundled @effect/platform-node require, both minified to n) and shows it reproduces on a separately built macOS artifact, not just the tagged build.

    Log

    ~/Library/Application Support/ai.opencode.desktop/logs/20261030T054345/main.log, right after the pane is first requested:

    [2026-10-30 13:44:11.464] [error] (main)  scope finalizer failed {
      scope: 'browser',
      error: "SyntaxError: Identifier 'n' has already been declared\n" +
        '    at compileSourceTextModule (node:internal/modules/esm/utils:320:16)\n' +
        '    at ModuleLoader.moduleStrategy (node:internal/modules/esm/translators:89:18)\n' +
        ...
    

    The entry is only written when the pane is actually loaded (opening the side panel), which is why a log grep at startup finds nothing.

    Why the UI gives no hint

    The launcher item is gated on available(session) && attached(session); attached requires the registration that this chunk load was supposed to provide. The failure is swallowed by the registration .catch(), so the menu item and the command disappear silently — consistent with #60444.

  3. Hona commented on Oct 30, 2026

    @Hona
    Member

    Fixed in 2.2.3 by #60430.

    The desktop main-process bundle declared require twice, which broke the in-app browser and its browser.* tools.

    Please update to 2.2.3. In the desktop app, use Check for Updates, or install it from the release page. If the browser pane still doesn't appear afterwards, please reopen this issue with your main.log from the logs folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions