From c6428eaff91fd8dc71e20e9a3f6f38106f08ab7c Mon Sep 17 00:00:00 2001 From: Patrick Dillon <pdillon@users.noreply.github.com> Date: Fri, 7 Oct 2016 10:12:53 -0400 Subject: [PATCH] Exit production build if any errors are in build stats (#859) * Exit on any errors passed in build stats * Match console error output in start.js --- packages/react-scripts/scripts/build.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/react-scripts/scripts/build.js b/packages/react-scripts/scripts/build.js index 4c61dc93b..d0b92f6a7 100644 --- a/packages/react-scripts/scripts/build.js +++ b/packages/react-scripts/scripts/build.js @@ -118,13 +118,27 @@ function printFileSizes(stats, previousSizeMap) { }); } +// Print out errors +function printErrors(summary, errors) { + console.log(chalk.red(summary)); + console.log(); + errors.forEach(err => { + console.log(err.message || err); + console.log(); + }); +} + // Create the production build and print the deployment instructions. function build(previousSizeMap) { console.log('Creating an optimized production build...'); webpack(config).run((err, stats) => { if (err) { - console.error('Failed to create a production build. Reason:'); - console.error(err.message || err); + printErrors('Failed to compile.', [err]); + process.exit(1); + } + + if (stats.compilation.errors.length) { + printErrors('Failed to compile.', stats.compilation.errors); process.exit(1); } -- GitLab