Skip to content

Conversation

@usvimal
Copy link

@usvimal usvimal commented Jan 5, 2026

Summary

  • Embeds all prompt content as string constants instead of reading from .txt files at runtime
  • Fixes compatibility issues with Bun's bundler where __dirname resolves incorrectly

Problem

When the package is bundled by Bun, the original approach using __dirname + readFileSync fails because __dirname resolves to incorrect paths at runtime. This causes errors like:

Cannot find module './lib/strategies' from 'C:\Users\...\node_modules\@tarquinen\opencode-dcp\dist\index.js'
ENOENT: no such file or directory, open '...\opencode-dcp\dist\lib\prompts\discard-tool-spec.txt'

Root Cause

Bun's bundler doesn't preserve __dirname semantics correctly when files are bundled. The .txt files exist in the package, but the runtime path resolution fails.

Solution

Embed all prompt content directly as string constants in lib/prompts/index.ts. This:

  • Eliminates filesystem access at runtime
  • Ensures compatibility with Bun and other ESM bundlers
  • Maintains the same loadPrompt() API

Testing

Tested locally by patching the installed package in ~/.cache/opencode/node_modules/@tarquinen/opencode-dcp/ - the errors are resolved and the package works correctly.

Changes

  • lib/prompts/index.ts: Replaced readFileSync approach with embedded string constants

The original approach using __dirname + readFileSync doesn't work correctly
when the package is bundled by Bun, as __dirname resolves to incorrect paths
at runtime. This causes 'Cannot find module' and 'ENOENT' errors.

This fix embeds all prompt content as string constants, eliminating the
need for filesystem access at runtime and ensuring compatibility with
Bun's bundler as well as other ESM bundlers.
@Tarquinen
Copy link
Collaborator

Is this necessary? I don't think the bundler is even used?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants