-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeScript Client Emitter Incorrectly Generates Browser Code with Direct Module Imports and Missing getClient
Implementation
#2974
Comments
@allenjzhang for awareness |
It sounds like a tshy bundle issue instead of codegen issue @mpodwysocki might have some thoughts here? |
@qiaozha maybe, I'm not familiar enough with how the various pieces work to say for sure, but I do see direct import statements in the generated code prior to building the client, see the last line in the code snippet below. Can tshy account for this somehow?
|
TL;DR: we will not bundle all codes into one file in The long story is we export our browser version code with node conditional exports under folder
You could also find the sample bundle project here, but let us know if any issue you meet! |
@MaryGao thanks for the link. I tried creating a bundle for the generated client code using webpack first, then rollup and I was unsuccessful with either bundler due to numerous errors. Has anyone been able to successfully create a bundle for unbranded client code generated from TypeSpec? |
The TypeSpec TypeScript client code emitter generates browser-specific output (located in the
dist/browser
directory) that incorrectly includes direct imports from the@typespec/ts-http-runtime
module, rather than bundling or replacing these imports with browser-compatible code.Detailed Description:
When generating a TypeScript client using TypeSpec, the emitter produces a
dist/browser
directory intended for browser usage. However, the generated JavaScript files within this directory still contain direct imports from the@typespec/ts-http-runtime
module, such as:This is incorrect because:
@typespec/ts-http-runtime
.dist/browser
Purpose: Thedist/browser
output is intended to be a self-contained bundle that does not rely on external Node.js modules at runtime.@typespec/ts-http-runtime
directly into thedist/browser
output or replace the import with a reference to a browser-specific implementation ofgetClient
that's already included in the bundle.Steps to Reproduce:
dist/browser
directory, for example anything that uses a client to interact with an API.@typespec/ts-http-runtime
.Environment:
Additional Information:
package.json
for@typespec/ts-http-runtime
correctly specifies a browser entry point in the"browser"
field.tshy
build process is configured to generate browser-specific output, but the generated code still contains the direct imports and lacks thegetClient
implementation.tspconfig.yaml
to specify that a browser client is desired.The text was updated successfully, but these errors were encountered: