From 5da717190381f57baa671638d340c6585da7df86 Mon Sep 17 00:00:00 2001 From: Max Falk Date: Sun, 6 Jun 2021 21:16:01 +0200 Subject: [PATCH] fix(cli): fix TypeError when formatting error messages error.errors can be undefined which will lead to a TypeError, swallowing the actual error message in the process Signed-off-by: Max Falk --- packages/cli/src/lib/builder/packager.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/cli/src/lib/builder/packager.ts b/packages/cli/src/lib/builder/packager.ts index ed76e23df3..2c85ec3df3 100644 --- a/packages/cli/src/lib/builder/packager.ts +++ b/packages/cli/src/lib/builder/packager.ts @@ -28,15 +28,17 @@ function formatErrorMessage(error: any) { if (error.code === 'PLUGIN_ERROR') { if (error.plugin === 'esbuild') { msg += `${error.message}\n\n`; - for (const { text, location } of error.errors) { - const { line, column } = location; - const path = relativePath(paths.targetDir, error.id); - const loc = chalk.cyan(`${path}:${line}:${column}`); + if (error.errors) { + for (const { text, location } of error.errors) { + const { line, column } = location; + const path = relativePath(paths.targetDir, error.id); + const loc = chalk.cyan(`${path}:${line}:${column}`); - if (text === 'Unexpected "<"' && error.id.endsWith('.js')) { - msg += `${loc}: ${text}, JavaScript files with JSX should use a .jsx extension`; - } else { - msg += `${loc}: ${text}`; + if (text === 'Unexpected "<"' && error.id.endsWith('.js')) { + msg += `${loc}: ${text}, JavaScript files with JSX should use a .jsx extension`; + } else { + msg += `${loc}: ${text}`; + } } } } else {