From 2518aab58822f4a57c1f4c24c1043d41ea0693e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Fri, 13 Aug 2021 11:11:06 +0200 Subject: [PATCH] Compensate for error formatting mismatch between Webpack 5 and react-dev-utils MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- .changeset/neat-days-sip.md | 5 +++++ packages/cli/src/lib/bundler/bundle.ts | 19 ++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 .changeset/neat-days-sip.md diff --git a/.changeset/neat-days-sip.md b/.changeset/neat-days-sip.md new file mode 100644 index 0000000000..b919c784d0 --- /dev/null +++ b/.changeset/neat-days-sip.md @@ -0,0 +1,5 @@ +--- +'@backstage/cli': patch +--- + +Compensate for error formatting mismatch between Webpack 5 and react-dev-utils diff --git a/packages/cli/src/lib/bundler/bundle.ts b/packages/cli/src/lib/bundler/bundle.ts index 082b1247ab..2f23d5cae6 100644 --- a/packages/cli/src/lib/bundler/bundle.ts +++ b/packages/cli/src/lib/bundler/bundle.ts @@ -117,9 +117,22 @@ async function build(compiler: webpack.Compiler, isCi: boolean) { if (!stats) { throw new Error('No stats provided'); } - const { errors, warnings } = formatWebpackMessages( - stats.toJson({ all: false, warnings: true, errors: true }), - ); + + const serializedStats = stats.toJson({ + all: false, + warnings: true, + errors: true, + }); + // NOTE(freben): The code below that extracts the message part of the errors, + // is due to react-dev-utils not yet being compatible with webpack 5. This + // may be possible to remove (just passing the serialized stats object + // directly into the format function) after a new release of react-dev-utils + // has been made available. + // See https://github.com/facebook/create-react-app/issues/9880 + const { errors, warnings } = formatWebpackMessages({ + errors: serializedStats.errors?.map(e => (e.message ? e.message : e)), + warnings: serializedStats.warnings?.map(e => (e.message ? e.message : e)), + }); if (errors.length) { // Only keep the first error. Others are often indicative