rescript-lang / rescript-lang/rescript-vscode

Binary resolution fails on Windows with ERR_INVALID_URL_SCHEME when compiler-info.json is missing

Open Beginner friendly
#1,184 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
ReScript
Stars
354
Forks
63
Avg merge
11h 29m
Merged PRs (30d)
1

Description

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.
await import(path)

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:

ERR_INVALID_URL_SCHEME

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the fallback binary-resolution code that imports targetPackagePath when compiler-info.json is missing, and review the change from PR #1177. Reproduce the Windows failure with the reported Node versions and verify that the fallback resolves the binary successfully without compiler-info.json; consider #1181 for related path-handling context.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
devtools
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.