From e2205261ac47e8e233fd69f66d3eaec4a6b69fa4 Mon Sep 17 00:00:00 2001 From: Nivesh353 Date: Wed, 22 Jul 2026 13:26:17 +0530 Subject: [PATCH] fix: use pathToFileURL for plugin entry import to support Windows paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Node's ESM loader requires a file:// URL for absolute paths on Windows — a raw "D:\..." path is misread as a URL with protocol "d:", causing plugin entry points to fail to load with "Received protocol 'd:'". Wrapping the path with pathToFileURL() fixes this on Windows while remaining correct on POSIX. Reproduced and verified live on Windows before the fix (exact predicted error), and confirmed no regression on POSIX after. --- src/plugins.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/plugins.ts b/src/plugins.ts index 8a22899..3031a91 100644 --- a/src/plugins.ts +++ b/src/plugins.ts @@ -1,5 +1,6 @@ import { readFile, readdir, stat, mkdir, rm } from "fs/promises"; import { join } from "path"; +import { pathToFileURL } from "url"; import { execFileSync } from "child_process"; import { createRequire } from "module"; import { homedir } from "os"; @@ -242,7 +243,11 @@ async function loadPlugin( const { createPluginApi } = await import("./plugin-sdk.js"); const api = createPluginApi(manifest.id, pluginDir, config); const entryPath = join(pluginDir, manifest.entry); - const mod = await import(entryPath); + // Node's ESM loader requires a file:// URL for absolute paths on + // Windows — a raw "D:\..." path is misread as a URL with protocol + // "d:", which the loader rejects. pathToFileURL() handles this + // correctly on every OS, including plain POSIX paths. + const mod = await import(pathToFileURL(entryPath).href); if (typeof mod.register === "function") { await mod.register(api); } else if (typeof mod.default === "function") {