Skip to content

Commit 18cd97d

Browse files
authored
fix: invalid ESM module path on Windows (#7162)
1 parent ef713bd commit 18cd97d

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Diff for: src/node/main.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { commit, version, vsRootPath } from "./constants"
99
import { register } from "./routes"
1010
import { VSCodeModule } from "./routes/vscode"
1111
import { isDirectory, open } from "./util"
12+
import * as os from "os"
1213

1314
/**
1415
* Return true if the user passed an extension-related VS Code flag.
@@ -51,7 +52,11 @@ export const runCodeCli = async (args: DefaultedArgs): Promise<void> => {
5152
try {
5253
// See vscode.loadVSCode for more on this jank.
5354
process.env.CODE_SERVER_PARENT_PID = process.pid.toString()
54-
const modPath = path.join(vsRootPath, "out/server-main.js")
55+
let modPath = path.join(vsRootPath, "out/server-main.js")
56+
if (os.platform() === "win32") {
57+
// On Windows, absolute paths of ESM modules must be a valid file URI.
58+
modPath = "file:///" + modPath.replace(/\\/g, "/")
59+
}
5560
const mod = (await eval(`import("${modPath}")`)) as VSCodeModule
5661
const serverModule = await mod.loadCodeWithNls()
5762
await serverModule.spawnCli(await toCodeArgs(args))

Diff for: src/node/routes/vscode.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { promises as fs } from "fs"
55
import * as http from "http"
66
import * as net from "net"
77
import * as path from "path"
8+
import * as os from "os"
89
import { WebsocketRequest } from "../../../typings/pluginapi"
910
import { logError } from "../../common/util"
1011
import { CodeArgs, toCodeArgs } from "../cli"
@@ -58,7 +59,11 @@ async function loadVSCode(req: express.Request): Promise<IVSCodeServerAPI> {
5859
// which will also require that we switch to ESM, since a hybrid approach
5960
// breaks importing `rotating-file-stream` for some reason. To work around
6061
// this, use `eval` for now, but we should consider switching to ESM.
61-
const modPath = path.join(vsRootPath, "out/server-main.js")
62+
let modPath = path.join(vsRootPath, "out/server-main.js")
63+
if (os.platform() === "win32") {
64+
// On Windows, absolute paths of ESM modules must be a valid file URI.
65+
modPath = "file:///" + modPath.replace(/\\/g, "/")
66+
}
6267
const mod = (await eval(`import("${modPath}")`)) as VSCodeModule
6368
const serverModule = await mod.loadCodeWithNls()
6469
return serverModule.createServer(null, {

0 commit comments

Comments
 (0)