[PR #10827] fix(bun): use --backend=copyfile to fix Windows CommonJS resolution #13568

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

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

State: open
Merged: No


Summary

Use --backend=copyfile when installing plugins via Bun to fix CommonJS module resolution issues on Windows.

Problem

When running opencode auth login on Windows, the command fails with:

Cannot find package 'fast-deep-equal' from '.../node_modules/find-my-way/index.js'

This happens because:

  1. @gitlab/opencode-gitlab-auth depends on fastifyfind-my-wayfast-deep-equal
  2. Bun's default installation uses symlinks (ReparsePoints on Windows) to link packages
  3. CommonJS require() resolution doesn't follow these symlinks correctly on Windows
  4. The resolution fails because fast-deep-equal cannot be found

Root Cause Analysis

Testing showed that:

  • --linker=isolated still uses Bun's .bun folder with symlinks
  • Windows symlinks (ReparsePoints) don't work correctly with Node's CommonJS resolution
  • The actual packages are stored in .bun folder but symlinked to node_modules

Solution

Add --backend=copyfile to the bun add command. This backend creates real file copies instead of symlinks, which CommonJS require() can resolve correctly.

Changes

  • packages/opencode/src/bun/index.ts: Add --backend=copyfile flag to bun add command

Testing

Tested on Windows 11 with:

  1. Clean cache: Remove-Item -Recurse ~/.cache/opencode
  2. Manual test: bun add --backend=copyfile @gitlab/opencode-gitlab-auth@1.3.2
  3. Verified fast-deep-equal exists as real directory (not symlink)
  4. Run opencode auth login → TUI loads successfully
  5. Built opencode from source with fix → works correctly

Related Issues

🤖 Generated with Claude Code

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/10827 **State:** open **Merged:** No --- ## Summary Use `--backend=copyfile` when installing plugins via Bun to fix CommonJS module resolution issues on Windows. ## Problem When running `opencode auth login` on Windows, the command fails with: ``` Cannot find package 'fast-deep-equal' from '.../node_modules/find-my-way/index.js' ``` This happens because: 1. `@gitlab/opencode-gitlab-auth` depends on `fastify` → `find-my-way` → `fast-deep-equal` 2. Bun's default installation uses symlinks (ReparsePoints on Windows) to link packages 3. CommonJS `require()` resolution doesn't follow these symlinks correctly on Windows 4. The resolution fails because `fast-deep-equal` cannot be found ## Root Cause Analysis Testing showed that: - `--linker=isolated` still uses Bun's `.bun` folder with symlinks - Windows symlinks (ReparsePoints) don't work correctly with Node's CommonJS resolution - The actual packages are stored in `.bun` folder but symlinked to `node_modules` ## Solution Add `--backend=copyfile` to the `bun add` command. This backend creates real file copies instead of symlinks, which CommonJS `require()` can resolve correctly. ## Changes - `packages/opencode/src/bun/index.ts`: Add `--backend=copyfile` flag to bun add command ## Testing Tested on Windows 11 with: 1. Clean cache: `Remove-Item -Recurse ~/.cache/opencode` 2. Manual test: `bun add --backend=copyfile @gitlab/opencode-gitlab-auth@1.3.2` 3. Verified `fast-deep-equal` exists as real directory (not symlink) 4. Run `opencode auth login` → TUI loads successfully 5. Built opencode from source with fix → works correctly ## Related Issues - Fixes #9870 🤖 Generated with [Claude Code](https://claude.ai/claude-code)
yindo added the pull-request label 2026-02-16 18:18:24 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13568