From 96e5dcb5f14b8d16520974b80bb531a190be2343 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Thu, 27 Feb 2025 10:41:39 -0500 Subject: [PATCH] fix(@angular/build): handle undefined `less` stylesheet sourcemap values There can be cases where the `less` stylesheet preprocessor will return an undefined value for a sourcemap even though sourcemaps have been enabled. A check is now performed to handle these cases to prevent potential crashes when processing `less` styles. (cherry picked from commit 25ea0986b1daa97d491ded3f1ef91bc0bc0284d7) --- .../build/src/tools/esbuild/stylesheets/less-language.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/angular/build/src/tools/esbuild/stylesheets/less-language.ts b/packages/angular/build/src/tools/esbuild/stylesheets/less-language.ts index 449e2b5c8d39..1b99100b90e9 100644 --- a/packages/angular/build/src/tools/esbuild/stylesheets/less-language.ts +++ b/packages/angular/build/src/tools/esbuild/stylesheets/less-language.ts @@ -130,7 +130,9 @@ async function compileString( } as Less.Options); return { - contents: options.sourcemap ? `${css}\n${sourceMapToUrlComment(map)}` : css, + // There can be cases where `less` will return an undefined `map` even + // though the types do not specify this as a possibility. + contents: map ? `${css}\n${sourceMapToUrlComment(map)}` : css, loader: 'css', watchFiles: [filename, ...imports], };