Skip to content

shuvcode fails with 'preload not found @opentui/solid/preload' when run from OpenTUI SolidJS projects #245

@shuv1337

Description

@shuv1337

Problem

When running shuvcode from within other OpenTUI SolidJS projects, the CLI fails immediately with:

error: preload not found "@opentui/solid/preload"

This does not happen with upstream opencode, and does not happen in other (non-OpenTUI) repositories.

Root Cause

This is caused by a known Bun bug (oven-sh/bun#25442): Bun applies the current working directory's bunfig.toml to hashbang scripts from linked/global packages.

How it happens:

  1. shuvcode is installed globally or linked
  2. User runs shuvcode from a directory that has its own bunfig.toml with:
    preload = ["@opentui/solid/preload"]
  3. Bun reads the CWD's bunfig.toml and tries to apply preloads
  4. Bun attempts to resolve @opentui/solid/preload from shuvcode's installation location (not the CWD)
  5. Resolution fails because @opentui/solid is a dependency of the local project, not the global shuvcode installation

Relevant files:

  • packages/opencode/bunfig.toml:1 - shuvcode's own preload configuration
  • packages/opencode/package.json:84 - @opentui/solid dependency

Acceptance Criteria

  • shuvcode can be launched from any directory, regardless of whether that directory has a bunfig.toml with preloads
  • The fix should work for both globally installed (bun install -g) and locally linked shuvcode
  • No regression in TUI functionality (SolidJS transforms must still work)

Potential Solutions

Option 1: Environment variable to disable config inheritance (Workaround)

Bun respects BUN_CONFIG_FILE - setting it to an empty value or a specific path might prevent CWD config loading:

# In the launcher script
BUN_CONFIG_FILE="" shuvcode "$@"

Reference: Bun config docs

Option 2: Move preload registration into the binary

Instead of relying on bunfig.toml, register the SolidJS plugin programmatically at startup:

// In src/index.ts or entry point
import { plugin } from "bun"
import solidTransformPlugin from "@opentui/solid/bun-plugin"

plugin(solidTransformPlugin)

This is what the preload script already does - see packages/opencode/node_modules/@opentui/solid/scripts/preload.ts:

import solidTransformPlugin from "./solid-plugin"
import { plugin, type BunPlugin } from "bun"

plugin(solidTransformPlugin)

Note: This approach requires careful consideration of module loading order.

Option 3: Use --config flag with explicit config path

Modify the launcher script to explicitly specify the config file:

bun --config /path/to/shuvcode/bunfig.toml run ...

Option 4: Wait for Bun fix

The upstream issue oven-sh/bun#25442 is open and describes this exact problem. However, there's no timeline for a fix.

Related Issues

  • Upstream Bun issue: oven-sh/bun#25442 - "Bun applies cwd's bunfig.toml to hashbang scripts from linked packages"
  • Similar issue: oven-sh/bun#12539 - "bunfig.toml cannot find preload script that doesn't begin with './'"

Environment

  • shuvcode version: 1.0.223+
  • Bun version: 1.3.x
  • Platform: Linux/macOS

Steps to Reproduce

  1. Have a project with bunfig.toml containing:
    preload = ["@opentui/solid/preload"]
  2. Install shuvcode globally: bun install -g shuvcode
  3. Navigate to the project directory
  4. Run shuvcode
  5. Observe the error: error: preload not found "@opentui/solid/preload"

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions