fix: convert Windows absolute paths to file URLs in ESM resolve hook - #152
Open
artnikbrothers wants to merge 6 commits into
Open
fix: convert Windows absolute paths to file URLs in ESM resolve hook#152artnikbrothers wants to merge 6 commits into
artnikbrothers wants to merge 6 commits into
Conversation
added 6 commits
August 18, 2026 18:57
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.
On Windows, aliased imports with
--import module-alias/registerfail withERR_UNSUPPORTED_ESM_URL_SCHEME ... Received protocol 'c:'. The resolve hooks pass the resolved path straight tonextResolve(), and Node parsesC:\...as a URL with protocolc:. On Linux/Mac it happens to work because/foo/baris also a valid URL, so the bug only shows on Windows.The fix is the same in both hooks (the sync one in
register.mjsfor Node 22.15+, the async one inesm-loader.mjsfor older Node): if the resolved path is absolute, convert it withpathToFileURL()first.init()had a similarstartsWith('/')check for alias targets, replaced it withpath.isAbsolute()too.Added windows-latest to CI plus unit tests for the resolve hook. The integration tests now pass
register.mjsto--importas a file URL, it was hitting the samec:problem. Green on Windows with Node 20 and 22.I also had to clean up CI a bit, because this is the first time the workflow runs against master at all (the triggers only listed dev, so master PRs never ran tests). The
NODE_ENV=testprefix in the test scripts breaks on Windows and nothing reads it, so I dropped it. Node 18 moved to the CJS-only job, mocha 2 loads.mjsthroughrequire()and that only works on Node 20.19+. The CJS suite stays Linux-only for now, two of its tests fail on Windows for reasons older than this PR. Same story with the Node 6 job, npm 3 simply can't install the dev dependencies anymore, it fails the same way without my changes.The bug exists in all versions that ship the ESM loader (2.3.0 - 2.3.4). Fixes #151