From edd9e30e63a5a2711f4fa645b1dccabd318ea997 Mon Sep 17 00:00:00 2001 From: Phillip Klawansky Date: Sun, 6 Feb 2022 05:46:47 +0200 Subject: [PATCH] Update font-stylesheet-gathering-plugin.ts (#30709) * Update font-stylesheet-gathering-plugin.ts For production build, getting an UnhandledPromiseRejectionWarning: Unhandled promise rejection on line 29. Added rejection handling callback to allow for builds. This breaks deployments to Vercel. * ensure font css minimizing errors are caught/logged Co-authored-by: JJ Kasper --- .../font-stylesheet-gathering-plugin.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/next/build/webpack/plugins/font-stylesheet-gathering-plugin.ts b/packages/next/build/webpack/plugins/font-stylesheet-gathering-plugin.ts index 66867f6cf60c8f..7c881255afafeb 100644 --- a/packages/next/build/webpack/plugins/font-stylesheet-gathering-plugin.ts +++ b/packages/next/build/webpack/plugins/font-stylesheet-gathering-plugin.ts @@ -13,6 +13,7 @@ import { FONT_MANIFEST, OPTIMIZED_FONT_PROVIDERS, } from '../../../shared/lib/constants' +import * as Log from '../../output/log' function minifyCss(css: string): Promise { return postcss([ @@ -197,11 +198,18 @@ export class FontStylesheetGatheringPlugin { const css = await fontDefinitionPromises[promiseIndex] if (css) { - const content = await minifyCss(css) - this.manifestContent.push({ - url: fontStylesheets[promiseIndex], - content, - }) + try { + const content = await minifyCss(css) + this.manifestContent.push({ + url: fontStylesheets[promiseIndex], + content, + }) + } catch (err) { + Log.warn( + `Failed to minify the stylesheet for ${fontStylesheets[promiseIndex]}. Skipped optimizing this font.` + ) + console.error(err) + } } }