Skip to content

fix(compiler): resolve packages located on UNC paths - #11998

Open
Scott Mc (scooter12) wants to merge 1 commit into
microsoft:mainfrom
scooter12:fix/11997-compiler-unc-module-resolution
Open

Scott Mc (scooter12) wants to merge 1 commit into
microsoft:mainfrom
scooter12:fix/11997-compiler-unc-module-resolution

Conversation

@scooter12

Copy link
Copy Markdown

Fixes #11997

Problem

tsp compile fails with INVALID_MODULE_EXPORT_TARGET when the project is on a Windows network share. A mapped drive letter fails too, because the path resolves to \\server\share\....

pathToFileURL in module-resolver/utils.ts returned file://${path}. For a UNC path //server/share/pkg this gave file:////server/share/pkg (4 slashes). resolvePath normalized the export target to file:///server/share/pkg/... (3 slashes). The resolvedTarget.startsWith(packageUrl) check in resolve-package-target.ts then failed.

Fix

One file, two functions:

  • pathToFileURL returns file://server/share/pkg for a UNC path. This is the same form as Node's url.pathToFileURL, and path-utils already handles file://server/ as a root.
  • fileURLToPath restores the leading // when the authority is not a drive letter.

Other paths give the same result as before.

Tests

  • utils.test.ts: pathToFileURL and fileURLToPath for POSIX and UNC paths, and a round trip for POSIX, drive letter, and UNC paths.
  • module-resolver.test.ts: a package with exports on a UNC path, and a project with imports on a UNC path. These use the existing mkFs helper.

5 of the new tests fail without the fix. 3 of them fail with the same INVALID_MODULE_EXPORT_TARGET / INVALID_MODULE_IMPORT_TARGET error as the issue.

`pathToFileURL` returned `file://${path}`. For a UNC path
`//server/share/pkg` this gave `file:////server/share/pkg`. `resolvePath`
normalized the export target to `file:///server/share/pkg/...`, so the
`startsWith(packageUrl)` check failed and `tsp compile` threw
`INVALID_MODULE_EXPORT_TARGET`.

`pathToFileURL` now returns `file://server/share/pkg` for UNC paths, the
same as Node's `url.pathToFileURL`. `fileURLToPath` restores the leading
`//` when the authority is not a drive letter.

Fixes microsoft#11997
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

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.

🟢 Approval recommended

The focused implementation and regression tests cover the reported UNC resolution failure.

Pull request overview

Fixes compiler module resolution for packages and imports located on Windows UNC paths.

Changes:

  • Corrects UNC path-to-file-URL conversion and reverse conversion.
  • Adds utility and module-resolution tests covering POSIX, drive-letter, and UNC paths.
  • Adds the compiler changelog entry.
File summaries
File Description
packages/compiler/src/module-resolver/utils.ts Fixes UNC URL conversion.
packages/compiler/test/module-resolver/utils.test.ts Tests URL conversion and round trips.
packages/compiler/test/module-resolver/module-resolver.test.ts Tests UNC package and import resolution.
.chronus/changes/fix-11997-compiler-unc-module-resolution-2026-09-17.md Documents the compiler bug fix.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@pkg-pr-new

pkg-pr-new Bot commented Sep 17, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/compiler@11998

commit: 042b2e6

@github-actions

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @typespec/compiler
Show changes

@typespec/compiler - fix ✏️

Fix tsp compile failing with INVALID_MODULE_EXPORT_TARGET when the project is on a Windows network share (UNC path).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Scott Mc (@scooter12) Thanks for the fix, I think this looks good just need to accept the CLA for the checks to pass #11998 (comment)

@scooter12

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler:core Issues for @typespec/compiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: tsp compile fails when the project is on a Windows network drive (UNC path)

3 participants