Skip to content

fix(@angular/build): inline external sourcemaps for workspace library files#32788

Open
JSMike wants to merge 1 commit intoangular:mainfrom
JSMike:sourceMappingURL
Open

fix(@angular/build): inline external sourcemaps for workspace library files#32788
JSMike wants to merge 1 commit intoangular:mainfrom
JSMike:sourceMappingURL

Conversation

@JSMike
Copy link
Contributor

@JSMike JSMike commented Mar 18, 2026

When no Babel plugins are required, the JavaScript transformer returns library
files as-is, preserving the //# sourceMappingURL comment but never reading
the referenced map file from disk. esbuild does not follow external sourcemap
links in input files, so the chain from bundled output back to the original
TypeScript source is never formed.

Read the external map file and return an inline base64 sourcemap instead.
esbuild processes inline sourcemaps from input files correctly, allowing it
to compose the full sourcemap chain through to the original TypeScript source.

Reproduction

A workspace library built with TypeScript (e.g. dist/libs/my-lib/index.js)
contains a //# sourceMappingURL=index.js.map comment. When an Angular
application imports from that library via a TypeScript path alias, the bundled
main.js.map includes the transpiled JS in sourcesContent ending with
//# sourceMappingURL=index.js.map, but the browser DevTools cannot resolve
the original TypeScript source because esbuild never followed the external
map reference.

Fix

When the early-return branch is taken (no Babel plugins needed), check for an
external sourceMappingURL reference, read the .map file from disk, and
return an inline base64 sourcemap. esbuild correctly chains inline sourcemaps
from input files, producing a complete map from bundle output back to the
original TypeScript source.

The catch block handles unreadable map files gracefully, falling back to the
original external reference.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request fixes an issue where external sourcemaps from workspace libraries are not inlined, which breaks the sourcemap chain in esbuild. The change correctly identifies external sourcemap URLs, reads the map file, and inlines it as a base64 data URI. The fallback mechanism for unreadable map files is also sensible. My review includes a suggestion to improve the implementation by using asynchronous file I/O and adding a warning for when a sourcemap file cannot be read, which will aid in debugging.

@JSMike JSMike force-pushed the sourceMappingURL branch 2 times, most recently from 3ec6e15 to 4fc722c Compare March 18, 2026 11:41
… files

When no Babel plugins are required, the JavaScript transformer returns library
files as-is, preserving the  comment but never reading
the referenced map file from disk. esbuild does not follow external sourcemap
links in input files, so the chain from bundled output back to the original
TypeScript source is never formed.

Read the external map file and return an inline base64 sourcemap instead.
esbuild processes inline sourcemaps from input files correctly, allowing it
to compose the full sourcemap chain through to the original TypeScript source.
@JSMike JSMike force-pushed the sourceMappingURL branch from 4fc722c to d72a80a Compare March 18, 2026 13:00
@JSMike
Copy link
Contributor Author

JSMike commented Mar 18, 2026

@alan-agius4 I just pushed some fixes. The initial PR was early, sorry about that. I've confirmed the fix locally. I'll be at the Angular Enterprise Summit in a couple of hours, see you there :) I could set up office hours with you if you'd like to review.

@JSMike
Copy link
Contributor Author

JSMike commented Mar 18, 2026

@alan-agius4
Copy link
Collaborator

Could you provide a minimal reproduction of this issue using ng new? Alternatively, an isolated E2E test case highlighting the regression would be highly beneficial for our debugging process.

Unless I am missing something from the above, in the first instance the source of the sourcemap is pointing to a JS file. Is this is original map of the TypeScript compilation for the library ?

{
  "version": 3,
  "sources": ["lib.js"],
  "sourcesContent": [
    "export const x = 1;\n//# sourceMappingURL=lib.js.map\n"
  ],
  "mappings": "AAAA"
}

@JSMike
Copy link
Contributor Author

JSMike commented Mar 18, 2026

@alan-agius4 working on my slides for tomorrow (where I discovered the issue), I have this in an NX monorepo right now if that helps, npx nx serve boxes-angular. I can work on a separate repro with ng new soon if it's still needed.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants