Skip to content

Fix file URL to path conversion in html-language-features esbuild script - #328557

Merged
Martin Aeschlimann (aeschli) merged 5 commits into
microsoft:mainfrom
jadefr:fix/html-language-features-esbuild-windows-path
Aug 19, 2026
Merged

Fix file URL to path conversion in html-language-features esbuild script#328557
Martin Aeschlimann (aeschli) merged 5 commits into
microsoft:mainfrom
jadefr:fix/html-language-features-esbuild-windows-path

Conversation

@jadefr

@jadefr Jade Ferreira Vieira (jadefr) commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Fix file URL to path conversion in html-language-features esbuild script

import.meta.resolve('typescript') returns a file:// URL, and the code converts it to a path with a plain string replace instead of a proper URL-to-path conversion.

The problem

Windows always fails: stripping file:// leaves /C:/Users/..., an invalid path (extra slash before the drive letter). Downstream path.join/fs calls resolve it against the current drive, producing a doubled path like C:\C:\Users\..., so npm run compile-web fails:

ENOENT: no such file or directory, open 'C:\C:\Users\...\lib\lib.es2020.full.d.ts'

Any OS fails too if the path contains a percent-encoded character — most commonly a space (e.g. ~/My Projects/...). The replace never decodes it, so file:///home/user/My%20Projects/.../typescript.js becomes a literal, nonexistent path — ENOENT again.

This went unnoticed because it needs either Windows, or a special character somewhere in the path — a plain path like ~/repos/vscode never triggers it. Windows hits it far more often in practice too: spaces are common in default Windows paths (C:\Program Files\, OneDrive - Company Name\), while Linux/macOS convention mostly avoids them.

The fix

fileURLToPath() (node:url) is Node's built-in, spec-correct URL-to-path converter — it handles both the drive-letter and percent-decoding cases. For simple paths it's a no-op on Linux/macOS; it only changes behavior where the old code was wrong.

Testing

Verified on Windows 11:

  • npm run compile-web and npm run compile-client — 0 errors (previously failed)
  • Runtime: opened a new .html file, typed <script> inside it, got correct JS/DOM IntelliSense — confirming the TypeScript lib .d.ts files actually load, not just that the build succeeds
  • Reproduced both failure modes in isolation (Windows drive-letter case, and percent-encoding case with a space in the path) and confirmed the fix resolves each
import.meta.resolve(...).replace('file://', '') is not a correct way
to convert a file:// URL to a filesystem path. It always breaks on
Windows (leaves a leading slash before the drive letter, e.g.
/C:/Users/..., which downstream path.join/fs calls mangle into
C:\C:\Users\...), and it also breaks on any OS whenever the resolved
path contains a character that gets percent-encoded in a URL, most
commonly a space (e.g. file:///home/jane%20doe/... never gets decoded
back to "jane doe", so fs.readFileSync fails with ENOENT there too).

Use fileURLToPath() from node:url instead, which is Node's own
built-in, spec-correct URL-to-path converter and handles both cases.
Copilot AI review requested due to automatic review settings August 1, 2026 12:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Corrects TypeScript library path resolution in the HTML language features browser build.

Changes:

  • Uses Node’s fileURLToPath() for Windows paths and percent-encoded characters.
@aeschli
Martin Aeschlimann (aeschli) merged commit e145e08 into microsoft:main Aug 19, 2026
27 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.135.0 milestone Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

6 participants