> ## Content Index
> Fetch the complete content index at: https://sgpublic.xyz/llms.txt
> Use this file to discover other available public pages before exploring further.

# OpenCode 在无头环境中报错 Error: Unexpected error
- URL: https://sgpublic.xyz/p/2026/07/6aac9cb1810a48000153361f/
- Published: 2026-07-12T03:48:56.000Z
- Updated: 2026-09-18T03:09:20.000Z
- Author: Haven Madray
- Tags: 基础设施, #wp-post

通过对 opencode 启动命令行添加参数 `--log-level DEBUG`，得到以下日志：

```
error: Executable not found in $PATH: "xdg-open"
      path: "xdg-open",
     errno: -2,
   syscall: "spawn xdg-open",
 spawnargs: [ "http://localhost:14096" ],
      code: "ENOENT"

      at spawn (node:child_process:667:35)
      at spawn (node:child_process:14:39)
      at <anonymous> (/$bunfs/root/chunk-m0dweyng.js:2:3353)

```

很明显 opencode 尝试调用 GUI 环境相关的命令，但这是个无头环境，相关 issue：[#31815 : opencode web shows ENOENT: xdg-open error in container environments](https://github.com/anomalyco/opencode/issues/31815?ref=sgpublic.xyz)，快速解决方案来自：[31815#issuecomment-4706666875](https://github.com/anomalyco/opencode/issues/31815?ref=sgpublic.xyz#issuecomment-4706666875)，即，运行以下命令即可：

```bash
sudo touch /usr/local/bin/xdg-open
sudo chmod +x /usr/local/bin/xdg-open

```