Environment
- OS: Windows 10 x64
- VS Code extension:
v1.73.11 (Pre-release)
- Language Server:
v1.72.0
- ReScript:
12.3.0
- Node: tested with 20.20.2, 22.23.1, and 24.18.0
Problem
When compiler-info.json is missing, the language server falls back to resolving binaries through:
await import(url.fileURLToPath(targetPackagePath))
On Windows this consistently throws:
TypeError [ERR_INVALID_URL_SCHEME]: The URL must be of scheme file
As a result, the language server cannot resolve ReScript binaries through the fallback path.
Investigation
This only happens when:
- ReScript version is >= 12.0.0-alpha.13
compiler-info.json does not exist, causing the fallback code path to execute.
If compiler-info.json exists (for example after a successful build), this code path is skipped, making the issue difficult to notice.
I reproduced the problem outside of the extension using a minimal Node script.
For the same filesystem path:
D:\...\node_modules\@rescript\win32-x64\bin.js
I tested all supported approaches.
1.
Result on Node 20, 22 and 24:
ERR_UNSUPPORTED_ESM_URL_SCHEME
2. (current implementation)
await import(fileURLToPath(path))
Result on Node 20, 22 and 24:
This happens because fileURLToPath() expects a file:// URL, but path is already a filesystem path.
3.
await import(pathToFileURL(path).href)
Result:
Works correctly on Node 20, Node 22 and Node 24.
Since the value being imported is already a filesystem path (as the variable name also suggests) and is immediately passed to import(), converting it with pathToFileURL() matches the intended Node.js API for dynamic ESM imports.
Although I only tested this on Windows, this should behave consistently across platforms because pathToFileURL() converts native filesystem paths into valid file:// URLs on both Windows and POSIX systems.
Expected fix
It looks like the fallback should import a file URL, not convert a filesystem path with fileURLToPath().
Replacing
await import(fileURLToPath(targetPackagePath))
with
await import(pathToFileURL(targetPackagePath).href)
resolved the issue in all of my Windows tests.
Since the imported value is already a filesystem path, this should also be the correct cross-platform approach rather than a Windows-specific workaround.
I also noticed that PR #1177 introduced the current fileURLToPath() implementation. Based on my testing, it looks like the original issue (await import(path)) was replaced with another issue caused by calling fileURLToPath() on an existing filesystem path.
This may also be related to #1181 since both issues involve Windows path handling during binary resolution.
Environment
v1.73.11(Pre-release)v1.72.012.3.0Problem
When
compiler-info.jsonis missing, the language server falls back to resolving binaries through:On Windows this consistently throws:
As a result, the language server cannot resolve ReScript binaries through the fallback path.
Investigation
This only happens when:
compiler-info.jsondoes not exist, causing the fallback code path to execute.If
compiler-info.jsonexists (for example after a successful build), this code path is skipped, making the issue difficult to notice.I reproduced the problem outside of the extension using a minimal Node script.
For the same filesystem path:
I tested all supported approaches.
1.
Result on Node 20, 22 and 24:
2. (current implementation)
Result on Node 20, 22 and 24:
This happens because
fileURLToPath()expects a file:// URL, butpathis already a filesystem path.3.
Result:
Works correctly on Node 20, Node 22 and Node 24.
Since the value being imported is already a filesystem path (as the variable name also suggests) and is immediately passed to
import(), converting it withpathToFileURL()matches the intended Node.js API for dynamic ESM imports.Although I only tested this on Windows, this should behave consistently across platforms because
pathToFileURL()converts native filesystem paths into validfile://URLs on both Windows and POSIX systems.Expected fix
It looks like the fallback should import a file URL, not convert a filesystem path with
fileURLToPath().Replacing
with
resolved the issue in all of my Windows tests.
Since the imported value is already a filesystem path, this should also be the correct cross-platform approach rather than a Windows-specific workaround.
I also noticed that PR #1177 introduced the current
fileURLToPath()implementation. Based on my testing, it looks like the original issue (await import(path)) was replaced with another issue caused by callingfileURLToPath()on an existing filesystem path.This may also be related to #1181 since both issues involve Windows path handling during binary resolution.