Skip to content

Commit e1f403f

Browse files
authored
fix(amazonq): avoid ERR_UNSUPPORTED_ESM_URL_SCHEME error when loading indexer on Windows (#1135)
## Problem The codewhisperer server fails to load the project context indexer on windows, raising a `ERR_UNSUPPORTED_ESM_URL_SCHEME ` failure. This happens when the library is imported with a regular path on Windows: https://github.com/aws/language-servers/blob/e4d4ef026c8a60cc1ddf08c981340a902d628016/server/aws-lsp-codewhisperer/src/shared/localProjectContextController.ts#L142-L143 Some information from nodejs/node#31710 indicates that code running on Windows must use URLs so that local file paths (including drive letters) are not mistakenly interpreted as things like http urls. ## Solution Wrap the path in a URL when running on Windows.
1 parent e4d4ef0 commit e1f403f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

server/aws-lsp-codewhisperer/src/shared/localProjectContextController.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import * as path from 'path'
2020

2121
import * as ignore from 'ignore'
2222
import { fdir } from 'fdir'
23+
import { pathToFileURL } from 'url'
2324

2425
const LIBRARY_DIR = (() => {
2526
if (require.main?.filename) {
@@ -139,7 +140,7 @@ export class LocalProjectContextController {
139140
`index worker thread count: ${indexWorkerThreads}`
140141
)
141142

142-
const libraryPath = path.join(LIBRARY_DIR, 'dist', 'extension.js')
143+
const libraryPath = this.getVectorLibraryPath()
143144
const vecLib = vectorLib ?? (await eval(`import("${libraryPath}")`))
144145
if (vecLib) {
145146
this._vecLib = await vecLib.start(LIBRARY_DIR, this.clientName, this.indexCacheDirPath)
@@ -153,6 +154,19 @@ export class LocalProjectContextController {
153154
}
154155
}
155156

157+
private getVectorLibraryPath(): string {
158+
const libraryPath = path.join(LIBRARY_DIR, 'dist', 'extension.js')
159+
160+
if (process.platform === 'win32') {
161+
// On Windows, the path must be loaded using a URL.
162+
// Using the file path directly results in ERR_UNSUPPORTED_ESM_URL_SCHEME
163+
// More details: https://github.com/nodejs/node/issues/31710
164+
return pathToFileURL(libraryPath).toString()
165+
}
166+
167+
return libraryPath
168+
}
169+
156170
public async dispose(): Promise<void> {
157171
if (this._vecLib) {
158172
await this._vecLib?.clear?.()

0 commit comments

Comments
 (0)