Skip to content

fix(core): use file:// URLs for local dynamic import() on Windows+Node#23639

Merged
Hona merged 2 commits intoanomalyco:devfrom
Hona:fix-import-error
Apr 21, 2026
Merged

fix(core): use file:// URLs for local dynamic import() on Windows+Node#23639
Hona merged 2 commits intoanomalyco:devfrom
Hona:fix-import-error

Conversation

@Hona
Copy link
Copy Markdown
Member

@Hona Hona commented Apr 21, 2026

Summary

  • convert local filesystem paths passed to dynamic import() into file:// URLs for Windows Node compatibility
  • keep existing behavior for imports that are already URLs; this change does not apply to bare module specifiers or virtual imports
  • fix the desktop/electron Windows failure where Node rejected raw absolute paths with Received protocol 'c:'

Notes

  • packages/opencode/src/tool/registry.ts: discovered tool files are absolute filesystem paths from Glob.scanSync(..., { absolute: true })
  • packages/opencode/src/provider/provider.ts: provider entrypoints are normalized only when they are local paths and left unchanged when already file://
  • Bun 1.3.10/1.3.11 and current real plugin packages tested cleanly with file:// for these paths; a separate Bun 1.3.10 Npm.add() package-layout issue is unrelated to this PR

Node's ESM loader on Windows rejects bare absolute paths for dynamic import()
and requires file:// URLs. This path is exercised by the Electron desktop app,
whose server runs in Node (not Bun), causing provider SDK loading and custom
tool discovery to fail with 'Received protocol c:'.

Always convert to pathToFileURL(...).href before import(); safe on Bun too.
Copilot AI review requested due to automatic review settings April 21, 2026 06:20
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes dynamic import() behavior on Windows under Node by consistently using file:// URLs when importing modules by absolute filesystem path, aligning tool/provider loading with Node’s ESM loader requirements.

Changes:

  • Tool registry plugin loader now always imports discovered tool files via pathToFileURL(...).href.
  • Provider SDK loader now normalizes non-file:// entrypoints to file:// URLs before dynamic import.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/opencode/src/tool/registry.ts Ensures tool modules discovered via glob are imported using file:// URLs for Windows+Node compatibility.
packages/opencode/src/provider/provider.ts Normalizes installed/local provider entrypoints to file:// URLs before importing to avoid Node ESM loader failures on Windows.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Hona Hona enabled auto-merge (squash) April 21, 2026 06:22
@Hona Hona disabled auto-merge April 21, 2026 06:24
@Hona Hona changed the title fix(app): use file:// URLs for dynamic import() on Windows+Node fix(core): use file:// URLs for local dynamic import() on Windows+Node Apr 21, 2026
@Hona Hona enabled auto-merge (squash) April 21, 2026 07:49
@Hona Hona merged commit 92c0058 into anomalyco:dev Apr 21, 2026
8 checks passed
xywsxp pushed a commit to xywsxp/opencode that referenced this pull request Apr 24, 2026
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.

3 participants