Skip to content

Commit 92c0058

Browse files
authored
fix(core): use file:// URLs for local dynamic import() on Windows+Node (#23639)
1 parent 224548d commit 92c0058

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

packages/opencode/src/provider/provider.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { zod } from "@/util/effect-zod"
1919
import { iife } from "@/util/iife"
2020
import { Global } from "../global"
2121
import path from "path"
22+
import { pathToFileURL } from "url"
2223
import { Effect, Layer, Context, Schema, Types } from "effect"
2324
import { EffectBridge } from "@/effect"
2425
import { InstanceState } from "@/effect"
@@ -1506,7 +1507,10 @@ const layer: Layer.Layer<
15061507
installedPath = model.api.npm
15071508
}
15081509

1509-
const mod = await import(installedPath)
1510+
// `installedPath` is a local entry path or an existing `file://` URL. Normalize
1511+
// only path inputs so Node on Windows accepts the dynamic import.
1512+
const importSpec = installedPath.startsWith("file://") ? installedPath : pathToFileURL(installedPath).href
1513+
const mod = await import(importSpec)
15101514

15111515
const fn = mod[Object.keys(mod).find((key) => key.startsWith("create"))!]
15121516
const loaded = fn({

packages/opencode/src/tool/registry.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ export const layer: Layer.Layer<
157157
if (matches.length) yield* config.waitForDependencies()
158158
for (const match of matches) {
159159
const namespace = path.basename(match, path.extname(match))
160-
const mod = yield* Effect.promise(
161-
() => import(process.platform === "win32" ? match : pathToFileURL(match).href),
162-
)
160+
// `match` is an absolute filesystem path from `Glob.scanSync(..., { absolute: true })`.
161+
// Import it as `file://` so Node on Windows accepts the dynamic import.
162+
const mod = yield* Effect.promise(() => import(pathToFileURL(match).href))
163163
for (const [id, def] of Object.entries<ToolDefinition>(mod)) {
164164
custom.push(fromPlugin(id === "default" ? namespace : `${namespace}_${id}`, def))
165165
}

0 commit comments

Comments
 (0)