[PR #10648] fix: ensure cache dir has package.json before bun install #13511

Open
opened 2026-02-16 18:18:21 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/10648

State: open
Merged: No


What does this PR do?

Fixes plugin installation failure when user has a package.json in their home directory
When running bun add --cwd <cache-dir> <package>, Bun traverses up from the target directory looking for a workspace root (a directory with package.json). If the user has a package.json in their home directory (e.g., ~/.git repo with package.json), Bun installs packages there instead of in the cache directory.
This causes the subsequent import() to fail with ERR_MODULE_NOT_FOUND because the packages aren't where OpenCode expects them.

Error example:
ERROR ... message=Cannot find module 'C:\Users....cache\opencode\node_modules\opencode-anthropic-auth' from 'B/~BUN/root/src/index.js'

Solution

Create the cache directory and an empty package.json before running bun add. This ensures Bun recognizes the cache directory as the
workspace root and installs packages there.

How did you verify your code works?

Verified by:

  1. Removing the cache directory
  2. Having a package.json in the home directory
  3. Running the install - packages now correctly install to the cache directory
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/10648 **State:** open **Merged:** No --- ### What does this PR do? Fixes plugin installation failure when user has a `package.json` in their home directory When running `bun add --cwd <cache-dir> <package>`, Bun traverses up from the target directory looking for a workspace root (a directory with `package.json`). If the user has a `package.json` in their home directory (e.g., `~/.git` repo with `package.json`), Bun installs packages there instead of in the cache directory. This causes the subsequent `import()` to fail with `ERR_MODULE_NOT_FOUND` because the packages aren't where OpenCode expects them. Error example: ERROR ... message=Cannot find module 'C:\Users\...\.cache\opencode\node_modules\opencode-anthropic-auth' from 'B/~BUN/root/src/index.js' ### Solution Create the cache directory and an empty `package.json` before running `bun add`. This ensures Bun recognizes the cache directory as the workspace root and installs packages there. ### How did you verify your code works? Verified by: 1. Removing the cache directory 2. Having a `package.json` in the home directory 3. Running the install - packages now correctly install to the cache directory
yindo added the pull-request label 2026-02-16 18:18:21 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13511