From d70498c7244b8d2406cf985fa7185f6dc7d08880 Mon Sep 17 00:00:00 2001 From: ChenPi11 <102936596+ChenPi11@users.noreply.github.com> Date: Sat, 11 Jan 2025 04:09:48 +0000 Subject: [PATCH 1/2] fix: invalid ESM module path on Windows --- src/node/main.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/node/main.ts b/src/node/main.ts index b3c4e4c14500..990a7af792b1 100644 --- a/src/node/main.ts +++ b/src/node/main.ts @@ -9,6 +9,7 @@ import { commit, version, vsRootPath } from "./constants" import { register } from "./routes" import { VSCodeModule } from "./routes/vscode" import { isDirectory, open } from "./util" +import * as os from "os" /** * Return true if the user passed an extension-related VS Code flag. @@ -51,7 +52,11 @@ export const runCodeCli = async (args: DefaultedArgs): Promise => { try { // See vscode.loadVSCode for more on this jank. process.env.CODE_SERVER_PARENT_PID = process.pid.toString() - const modPath = path.join(vsRootPath, "out/server-main.js") + let modPath = path.join(vsRootPath, "out/server-main.js") + if (os.platform() === "win32") { + // On Windows, absolute paths of ESM modules must be a valid file URI. + modPath = "file:///" + modPath.replace(/\\/g, "/") + } const mod = (await eval(`import("${modPath}")`)) as VSCodeModule const serverModule = await mod.loadCodeWithNls() await serverModule.spawnCli(await toCodeArgs(args)) From 7a86738e1ac248b43913503b38c4dca19946c3e1 Mon Sep 17 00:00:00 2001 From: ChenPi11 <102936596+ChenPi11@users.noreply.github.com> Date: Wed, 15 Jan 2025 11:22:56 +0000 Subject: [PATCH 2/2] fix: do the same in `src/node/routes/vscode.ts`. fix: invalid ESM module path on Windows. --- src/node/routes/vscode.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/node/routes/vscode.ts b/src/node/routes/vscode.ts index 7e8f0f3ff4e5..637a30352ceb 100644 --- a/src/node/routes/vscode.ts +++ b/src/node/routes/vscode.ts @@ -5,6 +5,7 @@ import { promises as fs } from "fs" import * as http from "http" import * as net from "net" import * as path from "path" +import * as os from "os" import { WebsocketRequest } from "../../../typings/pluginapi" import { logError } from "../../common/util" import { CodeArgs, toCodeArgs } from "../cli" @@ -58,7 +59,11 @@ async function loadVSCode(req: express.Request): Promise { // which will also require that we switch to ESM, since a hybrid approach // breaks importing `rotating-file-stream` for some reason. To work around // this, use `eval` for now, but we should consider switching to ESM. - const modPath = path.join(vsRootPath, "out/server-main.js") + let modPath = path.join(vsRootPath, "out/server-main.js") + if (os.platform() === "win32") { + // On Windows, absolute paths of ESM modules must be a valid file URI. + modPath = "file:///" + modPath.replace(/\\/g, "/") + } const mod = (await eval(`import("${modPath}")`)) as VSCodeModule const serverModule = await mod.loadCodeWithNls() return serverModule.createServer(null, {