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 <gmdfalk@gmail.com>
This commit is contained in:
Max Falk
2021-06-06 21:16:01 +02:00
committed by Fredrik Adelöw
parent 7e020e8a5d
commit 5da7171903
+10 -8
View File
@@ -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 {