Skip to content

fix(http-client-csharp): make emitter browser-bundleable for playground upload#10582

Merged
JoshLove-msft merged 1 commit into
microsoft:mainfrom
JoshLove-msft:fix/csharp-playground-bundle
May 1, 2026
Merged

fix(http-client-csharp): make emitter browser-bundleable for playground upload#10582
JoshLove-msft merged 1 commit into
microsoft:mainfrom
JoshLove-msft:fix/csharp-playground-bundle

Conversation

@JoshLove-msft
Copy link
Copy Markdown
Contributor

@JoshLove-msft JoshLove-msft commented May 1, 2026

Fixes the Upload playground bundle Azure DevOps pipeline step that was failing with:

packages/http-client-csharp/dist/emitter/src/emitter.js:5:24: ERROR: Could not resolve "path"
packages/http-client-csharp/dist/emitter/src/lib/utils.js:4:22: ERROR: Could not resolve "child_process"

Root cause

PR #10165 ("Add http client js to the playground", merged Apr 30) removed nodeModulesPolyfillPlugin from packages/bundler/src/bundler.ts. Until then, the bundler silently polyfilled Node built-ins like path, fs, and url (and stubbed child_process), which masked the fact that:

  • emitter.ts imports resolve from Node path.
  • lib/utils.ts imports spawn from child_process for execCSharpGenerator / execAsync, and lib/utils.ts is reached transitively from emitter.ts via shared helpers like getClientNamespaceString / isReadOnly.

The "browser" field in package.json only swaps emit-generate.js for emit-generate.browser.js — it doesn't help with these other files. With the polyfill plugin gone, the next C# publish run hit unresolved-module errors on those long-standing imports.

Fix

  1. Move execCSharpGenerator, execAsync, and processJsonRpc (the only child_process users) out of lib/utils.ts into a new lib/exec-utils.ts. lib/exec-utils.ts is only imported from emit-generate.ts (the Node-only generation entry point), so the browser bundle (which loads emit-generate.browser.ts via the browser field) never reaches it.
  2. Replace import { resolve } from "path" in emitter.ts with resolvePath from @typespec/compiler (the cross-platform TypeSpec utility used elsewhere in the emitter).
  3. Update tests to import from the new location.

This is the right fix even with the polyfill plugin in place — child_process was never going to work at runtime in the browser, so relying on the bundler to silently include it was a latent footgun.

Verified

  • npm run build:emitter
  • npm run test:emitter ✅ 205 passed (2 skipped)
  • Local esbuild bundle of dist/emitter/src/emitter.js for platform: 'browser' succeeds with no unresolved Node modules.

--generated by Copilot

…dleable

Moves the Node-only execCSharpGenerator/execAsync helpers (which use
child_process) out of lib/utils.ts and into a new lib/exec-utils.ts that
is only imported from emit-generate.ts (the Node-only generation entry
point). The browser variant (emit-generate.browser.ts) does not import
exec-utils, so child_process is no longer pulled into the browser bundle.

Also replaces `import { resolve } from "path"` in emitter.ts with the
cross-platform `resolvePath` utility from @typespec/compiler so that
emitter.ts no longer has a direct dependency on the Node `path` module.

This fixes the "Upload playground bundle" pipeline step that was failing
with:
  emitter.js: Could not resolve "path"
  lib/utils.js: Could not resolve "child_process"

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp label May 1, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 1, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-csharp@10582

commit: 1b21fdb

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

No changes needing a change description found.

@JoshLove-msft JoshLove-msft added this pull request to the merge queue May 1, 2026
Merged via the queue into microsoft:main with commit bea5e35 May 1, 2026
29 checks passed
@JoshLove-msft JoshLove-msft deleted the fix/csharp-playground-bundle branch May 1, 2026 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants