解决OpenCode无法在有Temp指向内存盘上时无法启动的问题
起因
我需要用OpenCode。平常我使用ImDisk创建了一个临时目录放在内存盘里,使用时偶尔会遇到一些问题不大的兼容性问题。
具体故障
启动私用Scoop安装的OpenCode后会卡死,什么都不输出,^C按下去也没有反应。如果是用npm安装的,或者是开启了输出日志,则会看到具体出现了什么问题:
INFO 2026-05-30T03:45:42 +127ms service=default worker shutting down
INFO 2026-05-30T03:45:42 +23ms service=file init
INFO 2026-05-30T03:45:42 +63ms service=db path=C:\Users\Floppy\.local\share\opencode\opencode.db opening database
INFO 2026-05-30T03:45:42 +7ms service=db count=20 mode=bundled applying migrations
INFO 2026-05-30T03:45:42 +27ms service=default disposing all instances
ERROR 2026-05-30T03:45:42 +463ms service=default name=Error message=Failed to initialize OpenTUI render library: Failed to open library "B:/~BUN/root/opentui-a7anrm45.dll": error code 126 stack=Error
at bD (B:/~BUN/root/chunk-9dg8905r.js:42:35988)
at c7 (B:/~BUN/root/chunk-9dg8905r.js:50:25234)
at <anonymous> (B:/~BUN/root/src/index.js:364:2399)
at processTicksAndRejections (unknown:7:39) fatal
解决
在 Issue Failed to initialize OpenTUI render library: Failed to open library. #3765 中,kommander的回复给出了一个解决办法。
这个问题是有Bun引发的,在Windows上会出现这个问题,解决办法是通过设置 BUN_TMPDIR 环境变量到一个正常的磁盘路径。
这个更改只对Bun有影响,其它应用将会继续把准备拉在临时目录里的屎拉在内存盘里。