Fix browser-targeting builds: move declare global from public-api.ts to export-api.ts#125014
Fix browser-targeting builds: move declare global from public-api.ts to export-api.ts#125014
declare global from public-api.ts to export-api.ts#125014Conversation
…o export-api.ts Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
declare global from public-api.ts to export-api.ts
There was a problem hiding this comment.
Pull request overview
Fixes a Browser/WASM build failure in the JavaScript type bundling pipeline by relocating a TypeScript declare global {} augmentation from a file that rollup-plugin-dts misclassifies as a “global module” to the rollup entrypoint module.
Changes:
- Removed
declare global { ... }frompublic-api.tsto avoid rollup exporting an ambient name. - Added the same
declare global { ... }block toexport-api.ts, which is already an explicit module/entrypoint for the d.ts bundle. - Regenerated
dotnet.d.tswith only ordering changes (API surface unchanged).
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/native/libs/Common/JavaScript/types/public-api.ts | Removes the ambient global augmentation that rollup-plugin-dts was incorrectly treating as an export. |
| src/native/libs/Common/JavaScript/types/export-api.ts | Adds the declare global augmentation to the rollup entrypoint module so bundling succeeds. |
| src/native/libs/Common/JavaScript/loader/dotnet.d.ts | Regenerated output reflecting the move (minor declaration reordering). |
|
@akoeplinger @pavelsavara The browser builds are on the floor across the board after the rollup npm package update from #124987 . The new version is more nit-picky. I am not sure why this was not caught by the CI in #124987 . |
|
|
|
@pavelsavara the rollup upgrade in src/mono went in with #124910 |
Description
Browser WASM builds fail with
rollup-plugin-dtsv6.2.3 + rollup 4.59.0:rollup-plugin-dtsclassifies a file as a "global module" if it has imports but no standaloneexport {}/export defaultstatement — causing all declared names to be treated as exports.public-api.tsuses only inline exports (export interface,export type, etc.), soisGlobalModule()returnstruefor it. This causes thedeclare global {}block's name"global"to be added to rollup's export list. Rollup 4.59.0 then strictly validates that every exported name resolves to a real variable, andglobal(a TypeScript ambient augmentation, not a variable) fails that check.Fix: Move
declare global {}frompublic-api.tstoexport-api.ts(the rollup entry point), which already has a standaloneexport { ... }statement that makesisGlobalModule()returnfalse. This matches the existing pattern in the Mono/browser runtime'sexport-types.ts.public-api.ts— removedeclare global {}export-api.ts— adddeclare global {}(entry point; correctly treated as scoped module)dotnet.d.ts(generated) — regenerated; semantically identical, minor declaration reorderingCustomer Impact
Browser/WASM targeting builds fail entirely — no output produced.
Regression
Yes, introduced by the rollup 4.59.0 package update which added strict validation that exported variable names resolve to real variables.
Testing
Reproduced the failure locally with the exact CI rollup invocation (
Configuration:RELEASE), confirmed it is resolved after the fix. TypeScript type check (tsc --noEmit) passes. Generateddotnet.d.tsoutput is semantically identical to pre-fix.Risk
Low. The change only affects where the
declare global {}augmentation lives in the TypeScript source. The generated.d.tsAPI surface is unchanged.Package authoring no longer needed in .NET 9
IMPORTANT: Starting with .NET 9, you no longer need to edit a NuGet package's csproj to enable building and bump the version.
Keep in mind that we still need package authoring in .NET 8 and older versions.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
helixr1107v0xdcypoyl9e7f.blob.core.windows.net/usr/bin/pwsh pwsh .github/skills/ci-analysis/scripts/Get-CIStatus.ps1 -BuildId 1314502 -ShowLogs(dns block)If you need me to access, download, or install something from one of these locations, you can either:
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.