Skip to content

Commit c6428ea

Browse files
pdillongaearon
authored andcommitted
Exit production build if any errors are in build stats (facebook#859)
* Exit on any errors passed in build stats * Match console error output in start.js
1 parent 410a6a9 commit c6428ea

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

packages/react-scripts/scripts/build.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,27 @@ function printFileSizes(stats, previousSizeMap) {
118118
});
119119
}
120120

121+
// Print out errors
122+
function printErrors(summary, errors) {
123+
console.log(chalk.red(summary));
124+
console.log();
125+
errors.forEach(err => {
126+
console.log(err.message || err);
127+
console.log();
128+
});
129+
}
130+
121131
// Create the production build and print the deployment instructions.
122132
function build(previousSizeMap) {
123133
console.log('Creating an optimized production build...');
124134
webpack(config).run((err, stats) => {
125135
if (err) {
126-
console.error('Failed to create a production build. Reason:');
127-
console.error(err.message || err);
136+
printErrors('Failed to compile.', [err]);
137+
process.exit(1);
138+
}
139+
140+
if (stats.compilation.errors.length) {
141+
printErrors('Failed to compile.', stats.compilation.errors);
128142
process.exit(1);
129143
}
130144

0 commit comments

Comments
 (0)