Fix file URL to path conversion in html-language-features esbuild script - #328557
Merged
Martin Aeschlimann (aeschli) merged 5 commits intoAug 19, 2026
Conversation
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 started reviewing on behalf of
Jade Ferreira Vieira (jadefr)
August 1, 2026 12:18
View session
Martin Aeschlimann (aeschli)
approved these changes
Aug 19, 2026
Martin Aeschlimann (aeschli)
enabled auto-merge (squash)
August 19, 2026 15:26
Raymond Zhao (rzhao271)
approved these changes
Aug 19, 2026
Dmitriy Vasyura (dmitrivMS)
approved these changes
Aug 19, 2026
Martin Aeschlimann (aeschli)
merged commit Aug 19, 2026
e145e08
into
microsoft:main
27 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix file URL to path conversion in html-language-features esbuild script
import.meta.resolve('typescript')returns afile://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). Downstreampath.join/fscalls resolve it against the current drive, producing a doubled path likeC:\C:\Users\..., sonpm run compile-webfails: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, sofile:///home/user/My%20Projects/.../typescript.jsbecomes a literal, nonexistent path —ENOENTagain.This went unnoticed because it needs either Windows, or a special character somewhere in the path — a plain path like
~/repos/vscodenever 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-webandnpm run compile-client— 0 errors (previously failed).htmlfile, typed<script>inside it, got correct JS/DOM IntelliSense — confirming the TypeScript lib.d.tsfiles actually load, not just that the build succeeds