Skip to content

fix: replace NodeJS.ReadableStream with platform-conditional NodeReadableStream in RLC generated code#3998

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-rlc-bytes-request-body
Draft

fix: replace NodeJS.ReadableStream with platform-conditional NodeReadableStream in RLC generated code#3998
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-rlc-bytes-request-body

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 22, 2026

RLC emitter generates NodeJS.ReadableStream inline in binary request body type unions, which breaks browser builds that exclude @types/node (TS2503). This affects any data-plane service with bytes request bodies.

Changes

  • packages/typespec-ts/src/utils/modelUtils.ts — Replace NodeJS.ReadableStream with NodeReadableStream in BINARY_TYPE_UNION
  • packages/rlc-common/src/buildParameterTypes.ts — Emit import type { NodeReadableStream } from platform-types when binary types are present in generated parameters
  • packages/rlc-common/src/buildSchemaType.ts — Same import logic for generated model files
  • packages/rlc-common/src/buildObjectTypes.ts — Update isBinaryArray() detection to match new type name

For azureSdkForJs packages the import uses #platform/static-helpers/platform-types.js (subpath import), otherwise a relative path. The existing platform-types static helper resolves to NodeJS.ReadableStream on Node and never on browser, so the union arm drops out naturally in browser builds.

// Before (breaks browser build)
body: string | Uint8Array | ReadableStream<Uint8Array> | NodeJS.ReadableStream;

// After (platform-conditional)
import type { NodeReadableStream } from "#platform/static-helpers/platform-types.js";
body: string | Uint8Array | ReadableStream<Uint8Array> | NodeReadableStream;

…form/ import in RLC generated code

Replace inline NodeJS.ReadableStream type references with
NodeReadableStream imported from platform-types static helper.
This uses the #platform/ subpath import pattern (for azureSdkForJs)
so that browser builds resolve to `never` and Node builds resolve
to the actual NodeJS.ReadableStream type.

Agent-Logs-Url: https://github.com/Azure/autorest.typescript/sessions/197375da-5572-4d2b-9001-6e387e9f043d

Co-authored-by: jeremymeng <7583839+jeremymeng@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix RLC emitter bytes request body for browser builds fix: replace NodeJS.ReadableStream with platform-conditional NodeReadableStream in RLC generated code May 22, 2026
Copilot AI requested a review from jeremymeng May 22, 2026 18:12
// Add NodeReadableStream import if binary types are used in models
if (modelsFile.getFullText().includes("NodeReadableStream")) {
const platformTypesModuleSpecifier = model.options?.azureSdkForJs
? "#platform/static-helpers/platform-types.js"
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.

Suggested change
? "#platform/static-helpers/platform-types.js"
? "#platform/static-helpers/platform-types"

@siddharthUCD
Copy link
Copy Markdown

Hi Team, Just checking in. No rush I just wanted to know when is the expected merge/deployment date for this change since we have an API committee review coming up on Tuesday. Would be helpful to have an ETA. Thank you

CC: @qiaozha @kazrael2119

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

Labels

HRLC p0 priority 0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RLC: bytes request body emits NodeJS.ReadableStream union arm, breaking browser build (TS2503)

5 participants