From 38ac49b799c4c4b2c3d958110271d2e8244fa15b Mon Sep 17 00:00:00 2001 From: Alan Agius <17563226+alan-agius4@users.noreply.github.com> Date: Mon, 10 Mar 2025 08:19:20 +0000 Subject: [PATCH] fix(@angular/build): handle postcss compilation errors gracefully Improves error handling in the PostCSS compilation process to prevent crashes and allow recovery. Closes #29789 --- .../stylesheets/stylesheet-plugin-factory.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/angular/build/src/tools/esbuild/stylesheets/stylesheet-plugin-factory.ts b/packages/angular/build/src/tools/esbuild/stylesheets/stylesheet-plugin-factory.ts index 0e99212adbc8..f618bbf6cc39 100644 --- a/packages/angular/build/src/tools/esbuild/stylesheets/stylesheet-plugin-factory.ts +++ b/packages/angular/build/src/tools/esbuild/stylesheets/stylesheet-plugin-factory.ts @@ -12,6 +12,7 @@ import { readFile } from 'node:fs/promises'; import { extname } from 'node:path'; import type { Options } from 'sass'; import { glob } from 'tinyglobby'; +import { assertIsError } from '../../../utils/error'; import type { PostcssConfiguration } from '../../../utils/postcss-configuration'; import { LoadResultCache, createCachedLoad } from '../load-result-cache'; @@ -422,8 +423,16 @@ async function compileString( }, ], }; - } + } else { + assertIsError(error); - throw error; + return { + errors: [ + { + text: error.message, + }, + ], + }; + } } }