Skip to content

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

Merged
Hona merged 2 commits into
anomalyco: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 into
anomalyco:devfrom
Hona:fix-import-error

Conversation

@Hona

@HonaHona commented Apr 21, 2026

Copy link
Copy Markdown
Member

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.
CopilotAI review requested due to automatic review settings April 21, 2026 06:20

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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.

FileDescription
packages/opencode/src/tool/registry.tsEnsures tool modules discovered via glob are imported using file:// URLs for Windows+Node compatibility.
packages/opencode/src/provider/provider.tsNormalizes 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
@HonaHona changed the title fix(app): use file:// URLs for dynamic import() on Windows+Nodefix(core): use file:// URLs for local dynamic import() on Windows+NodeApr 21, 2026
@Hona
Hona enabled auto-merge (squash) April 21, 2026 07:49
@Hona
Hona merged commit 92c0058 into anomalyco:devApr 21, 2026
8 checks passed
metyatech pushed a commit to metyatech/opencode that referenced this pull request Apr 22, 2026
princevijay27 pushed a commit to princevijay27/opencode that referenced this pull request Apr 28, 2026
AIALRA-0 pushed a commit to AIALRA-0/opencode-turn-engine that referenced this pull request Jun 10, 2026
AIALRA-0 pushed a commit to AIALRA-0/opencode-turn-engine that referenced this pull request Jun 10, 2026
isaacfinnegan pushed a commit to isaacfinnegan/whispercode that referenced this pull request Jun 15, 2026
MarsQiu007 referenced this pull request in MarsQiu007/openNovel Jul 31, 2026
Sign up for freeto 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

@Hona@Brendonovich